Re: replace substring



On Mon, May 26, 2008 at 12:29:05AM -0700, James Dow Allen wrote:
On May 26, 2:06 pm, magix <mag...@xxxxxxxxx> wrote:
I want to replace all the "\" to be "\\", so that

Try
sed ss\\\\s\\\\\\\\sg
This sed solution seems to be off-topic, but, when applied to the OP's
source, could fix the C problem.

The OP should tell how he got that invalid string literal. If it his
own typing, he should replace the backslashes with pairs of backslashes,
either by hand or using the sed script above. (But it is unlikely to have
sed on a platform with path names containing lot's of backslashes.)

(you=OP)
On the other hand, it is an interesting question, how to replace
valid backslash characters in a string to pairs of backslashes, which can
be relevant, e.g. when writing a source code or passing the string to an
other picky application. If that is the case, you can do this replacement
on the course of copying each character to a separate character array.

Third point is, that it is possible to put a string into a character
array , like char path[]="d:\\path"; This character array cannot hold
more characters than it did originally, but feel free to put a big number
between the square brackets so that you do not have this limitation.
(This point is surely covered by the faq)

Szabolcs

YMMV

James Dow Allen
.



Relevant Pages

  • Re: strange transliteration in win32com.client
    ... the \ character in a string ... When Python prints out a string in its "repr", ... \myaccessdb.mdb' is not a valid path. ... You can avoid quoting all backslashes by using raw strings ...
    (comp.lang.python)
  • Re: Use parentheses in translation strings
    ... i tried the unsubscribe email and the help email addy for this list, i still cant unsubscribe, the emails produce no results/returned emails etc. ugh. ... remove the backslashes before brackets, ... the corresponding character from the list on the right. ... You want to use the s/// operator, which will replace the string ...
    (perl.beginners)
  • Re: Use parentheses in translation strings
    ... shouldn't the backslash escape the round brackets? ... remove the backslashes before brackets, ... the corresponding character from the list on the right. ... You want to use the s/// operator, which will replace the string ...
    (perl.beginners)
  • Re: Advice needed binary configuration files
    ... Just typing for something to do. ... convert the character buffer to the long type. ... And so on and so on till you get to the string. ... Regards, ...
    (microsoft.public.vc.mfc)
  • Re: Use parentheses in translation strings
    ... remove the backslashes before brackets, ... the target string it with the string in the second part. ... corresponding character from the second argument in the target string. ... Mongolian digit one). ...
    (perl.beginners)