problem while trimming the NSstring in objective c in an iphone app
i have a string like "qytwyqteqe" i want only qytwyqteqe but not the symbol ""
i tried to trim this string using the following code but its giving error can any one help me pls, thanx in advance
[[strTrimmedDownloadedDirNames replaceOccurrencesOfString:@""" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [strTrimmedDownloadedDirNames length])];
its giving error for this one @"""
error: missing terminating ""
edited:
actually i have an array like this
arrConvertedDirNames:(
"(\n \"(\\n \\\"Sudha-feb16-2011-02.30PM\\\"\\n)\"",
"\n \"Tharanga-jan16-2011-10.30AM\"\n)\n"
)
i have done following replacements to remove escaping sequence
NSMutableString *strTrimmedDownloadedDirNames = [NSMutableString stringWithFormat:@"%@",[arrDownloadedDirNames objectAtIndex:0]];
[strTrimmedDownloadedDirNames replaceOccurrencesOfString:@"\\\"" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [strTrimmedDownloadedDirNames length])];
[strTrimmedDownloadedDirNames replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [strTrimmedDownloadedDirNames length])];
[strTrimmedDownloadedDirNames replaceOccurrencesOfString:@"\n \"" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [strTrimmedDownloadedDirNames length])];
[strTrimmedDownloadedDirNames replaceOccurrencesOfString:@"\"\n" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [strTrimmedDownloadedDirNames length])];
[strTrimmedDownloadedDirNames replaceOccurrencesOfString:@"\\n" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [strTrimmedDownloadedDirNames length])];
[strTrimmedDownloadedDirNames replaceOccurrencesOfString:@")" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [strTrimmedDownloadedDirNames length])];
[strTrimmedDownloadedDirNames replaceOccurrencesOfString:@"(" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [strTrimmedDownloadedDirNames length])];
[strTrimmedDownloadedDirNames replaceOccurrencesOfString:@")\" " withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [strTrimmedDownloadedDirNames length])];
[strTrimmedDownloadedDirNames replaceOccurrencesOfString:@"\"" withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [strTrimmedDownloadedDirNames length])];
[strTrimmedDownloadedDirNames replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [strTrimmedDownloadedDirNames length])];
[strTrimmedDownloadedDirNames replaceOccurrencesOfString:@"\"" withString:@" " options:NSLiteralSearch range:NSMakeRange(0, [strTrimmedDownloadedDirNames length])];
now am getting this array
arrConvertedDirNames:(
"Sudha-feb16-2011-02.30PM",
"Tharanga-jan16-2011-10.30AM"
)
but this array should be like this
arrConvertedDirNames:(
Sudha-feb16-2011-02.30PM ,
Thar开发者_Python百科anga-jan16-2011-10.30AM
)
what can be done to make array so,, please can any one help me
You need to escape the "
, meaning:
this: replaceOccurrencesOfString:@"""
should be: replaceOccurrencesOfString:@"\""
NSCharacterSet *charterSet = [NSCharacterSet characterSetWithCharactersInString:@"""];
stringWithoutCurrentSymbol = [stringWithAnySimbols stringByTrimmingCharactersInSet:charterSet];
be carefully Returns a new string made by removing from both ends of the receiver characters contained in a given character set.
精彩评论