discuss-gnustep
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: problem with NSString's stringByReplacingOccurrencesOfString


From: Sebastian Reitenbach
Subject: Re: problem with NSString's stringByReplacingOccurrencesOfString
Date: Sun, 11 Nov 2012 14:29:19 +0100
User-agent: SOGoMail 2.0.2

 
On Sunday, November 11, 2012 14:11 CET, Tom Davie <tom.davie@gmail.com> wrote: 
 
> 
> On 11 Nov 2012, at 13:07, "Sebastian Reitenbach" 
> <sebastia@l00-bugdead-prods.de> 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.

Doh!. That works, many thanks.
With all my trials, I found this working:
escapedFileName = [@"this is a string' blah" 
stringByReplacingOccurrencesOfString:@"'" withString:@"XXXX"];
just to make sure, I retested with @"'" and with @"\'" as the first sring, and 
I get to the same result.
My first mail was a bit wrong here with that test I mentioned. That the @"'" 
worked for the first string, I did not
assumed I need that many backslashes for the second ;)

thanks Tom,

Sebastian

> 
> Tom Davie 
 
 
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]