string.replace() can't replace newline characters??? 
Author Message
 string.replace() can't replace newline characters???

I have a string with newline characters in it that I want to replace with
text.  My code goes

value = string.replace(qs[x][0], "\n", "'+char(10)+'")

The result is a new string with the text "'+char(10)+'" **AFTER** each newline
character.

Help?



Tue, 28 Jan 2003 03:00:00 GMT  
 string.replace() can't replace newline characters???
[posted & mailed]

[Thomas Gagne]

Quote:
> I have a string with newline characters in it that I want to
> replace with text.  My code goes

> value = string.replace(qs[x][0], "\n", "'+char(10)+'")

> The result is a new string with the text "'+char(10)+'" **AFTER**
> each newline character.

You're probably suffering from an illusion, but hard to guess what if you
don't show us *why* you think this is happening.  Here's why I think it
isn't:

C:\Python16>python
python 1.6a2 (#0, Apr  6 2000, 11:45:12) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam

Quote:
>>> import string
>>> test = "1\n2\n3\n"  # test string w/ 3 newlines
>>> test
'1\0122\0123\012'
>>> string.replace(test, "\n", "'+char(10)+'")

"1'+char(10)+'2'+char(10)+'3'+char(10)+'"

So there are no newlines in the result when I do it.  Show us what happens
when you do it.



Tue, 28 Jan 2003 03:00:00 GMT  
 string.replace() can't replace newline characters???
Nevermind.  The string, from a CGI GET, had both \012\015 and not just one or
the other.  I was replacing one and leaving the other.  Sigh.


Tue, 28 Jan 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Issues with Non-COBOL characters and REPLACE / REPLACING

2. Replace Nth Character in a String

3. Replace Characters in a String

4. Using string map to replace Special Characters (MS Word)

5. Replace a character in a string

6. Replacing characters in a string

7. Function for replacing characters that can't be used in a filename

8. REPLACE not replacing under Win 95??

9. How to replace or create a file using the open/create/replace.vi

10. Replacing 2 end characters

11. Replace a sequence of characters

12. replacing ^M characters with linefeed

 

 
Powered by phpBB® Forum Software