Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete characters in a string? 1

Status
Not open for further replies.

randi

Programmer
Jun 20, 2000
3
US
I'm trying to delete all instances of . , ' ( ) in a string
char *mystring

I'm not sure how to do this - the compiler won't let me substitute with an empy string. (i.e., mystring[0] = ''; doesn't work).

Is tokenization and concatenation the way to go or is there a simpler function I am missing?

Thanks.

 
for(int q=0;q<strlen(my_string);q++)
if ((my_string[q]=='.') || (my_string[q]==',') || (my_string[q]==')') || (my_string[q]=='('))
{
for (int w=q;w<strlen(my_string)-1;w++)
my_string[w]=my_string[w+1);
my_string[w+1]='\0';
}

Best Regards,

aphrodita@mail.krovatka.ru {uiuc rules}
 
Yes this absolutely worked. Thanks a lot for generously writing out that code for me. For anyone also using this, do these 2 minor tweaks.
(1) comment out the parenthesis with a backslash
(my_string[q]=='\)')

(2) the inner loop constraint is just w<strlen(my_sting);

I went to uiuc too. :)

Thanks,
Rebecca Andino
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top