objective c - stringByTrimmingCharactersInSet: - not tripping a disalllowed '%'? -
for odd reason; stringbytrimmingcharacterinset: allows '%' through.
why ?
simple code demonstrates issue (meant phone # text):
nsstring * allowedset = @"01234567890+-#"; nscharacterset * disallowedset =[[nscharacterset charactersetwithcharactersinstring:allowedset] invertedset]; in = @"+31%121212abc"; out = [in stringbytrimmingcharactersinset:disallowedset];
i have expected output
... in : +31%121212abc ... out : +31121212
but getting:
... in : +31%121212abc ... out : +31%121212
why ? seems work pretty other chars. '%' special - or odd url related issue ?
i trimming string; opposed replacing chars. ignores not @ start or end; i.e. chars in middle of string. using stringbyreplacingcharactersinset: resolves nicely.
@interface nsstring (inefficientstringbyremovingcharactersinset) - (nsstring *)stringbyremovingcharactersinset:(nscharacterset *)characterset; @end @implementation nsstring (inefficientstringbyremovingcharactersinset) - (nsstring *)stringbyremovingcharactersinset:(nscharacterset *)characterset { return [[self componentsseparatedbycharactersinset:characterset] componentsjoinedbystring:@""]; } @end
Comments
Post a Comment