On 11 Nov 2012, at 13:07, "Sebastian Reitenbach" <[email protected]> wrote:
> 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 You have missed a quote, @"\'" is the string containing only a single quote, so you're asking it to replace quotes with the same quotes. You wanted @"\'" in the first instance, and @"\\\'" in the second. Tom Davie _______________________________________________ Discuss-gnustep mailing list [email protected] https://lists.gnu.org/mailman/listinfo/discuss-gnustep
