if you know where in the string the character is, then its as simple as just writing over it. If you dont know where it is, then you have to do a loop and search through the string to find it, then write over it.
example 1: The string char mystring[] = "Hello World." you want to replace the . with !. your code would be:
mystring[11] = '!';
the . is the 11'th element in the string.
example 2: you want to replace . with !, but dont know where it is in the string. the code would be:
for (int count = 0; count < sizeof(mystring); count++)
{
if (mystring[count] == '.')
{
mystring[count] = '!';
break;
}
}
2006-09-14 02:04:18
·
answer #1
·
answered by justme 7
·
0⤊
0⤋
C String Replace Character
2016-10-30 08:13:40
·
answer #2
·
answered by umpierrez 4
·
0⤊
0⤋
You have to loop through each character in that string and replace it with a character of your desire.
Ex:
for(x = 0; x < strlen(text); x++)
{
text[x] = 'X';
}
For more free C/C++ source codes, visit: http://smartcoder.co.nr
KaBalweg
http://smartcoder.co.nr
2006-09-14 01:49:37
·
answer #3
·
answered by dabsani 3
·
0⤊
0⤋
delete tat character and add another
2006-09-14 01:32:53
·
answer #4
·
answered by Alexander R 1
·
0⤊
1⤋