[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
problem with NSString's stringByReplacingOccurrencesOfString
From: |
Sebastian Reitenbach |
Subject: |
problem with NSString's stringByReplacingOccurrencesOfString |
Date: |
Sun, 11 Nov 2012 14:07:14 +0100 |
User-agent: |
SOGoMail 2.0.2 |
Hi,
I try to replace "'" with "\'", and also "\\" with "\\\\" using NSString's
stringByReplacingOccurrencesOfString.
When I for example do this:
escapedFileName = [@"this is a string blah"
stringByReplacingOccurrencesOfString:@"blah" withString:@"blubb"];
NSLog(@"escapedFileName: %@", escapedFileName);
Then it prints out:
escapedFileName: this is a string blubb
So far, so good.
but when I then try to:
escapedFileName = [@"this is a string' blah"
stringByReplacingOccurrencesOfString:@"'" withString:@"\'"];
then the NSLog prints out:
escapedFileName: this is a string' blah
also when I try:
escapedFileName = [@"this is a string' blah"
stringByReplacingOccurrencesOfString:@"'" withString:@"XXX"];
its still printing:
escapedFileName: this is a string' blah
also I have a problem when I try to escape \ characters:
escapedFileName = [@"this is a string\ blah"
stringByReplacingOccurrencesOfString:@"blah" withString:@"blubb"];
prints:
escapedFileName: this is a string blubb
which replaced blah with blubb, but the backslash is also gone.
therefore, this doesn't work either:
escapedFileName = [@"this is a string\ blah"
stringByReplacingOccurrencesOfString:@"\\" withString:@"\\\\"];
just strips the backslash, instead of replacing it. NSLog prints:
escapedFileName: this is a string blah
I'm now wondering what the heck I'm doing wrong here?
Any hit with a cluestick is appreciated.
Its gnustep-base 1.24.0 I am using.
cheers,
Sebastian
- problem with NSString's stringByReplacingOccurrencesOfString,
Sebastian Reitenbach <=