Discussion: replace substring
Afficher un message
Vieux 30/05/2008, 18h42   #12
Keith Thompson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: replace substring

CBFalconer <cbfalconer@yahoo.com> writes:
> magix wrote:
>>
>> I have
>> char* str1 = "d:\temp\data\test.txt"
>>
>> I want to replace all the "\" to be "\\", so that
>> the string will have "d:\\temp\\data\\test.txt"
>>
>> Can you ?

>
> No. str1 is a non-writable string. You can create str2 and copy
> str1, with modifications, into it. The copy part will look
> something like:
>
> while (*p1) {
> if ('\' == (*p2++ = *p1++)) *p2++ = '\';
> }


Note that '\' is a syntax error. It should be '\\'.

--
Keith Thompson (The_Other_Keith) kst-u@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
  Réponse avec citation
 
Page generated in 0,05219 seconds with 9 queries