在iphone应用程序中修剪目标c中的NSstring时出现问题

时间:2011-08-24 13:18:47

标签: iphone objective-c nsstring trim

我有一个像“qytwyqteqe”的字符串我只想要qytwyqteqe而不是符号“”

我尝试使用以下代码修剪此字符串,但是它的给出错误可以帮助我,任何人帮助我,提前

   [[strTrimmedDownloadedDirNames replaceOccurrencesOfString:@"""  withString:@"" options:NSLiteralSearch range:NSMakeRange(0, [strTrimmedDownloadedDirNames length])];

its giving error for this one @""" 
error:  missing terminating ""

编辑:

实际上我有一个像这样的数组

arrConvertedDirNames:(
    "(\n    \"(\\n    \\\"Sudha-feb16-2011-02.30PM\\\"\\n)\"",
    "\n    \"Tharanga-jan16-2011-10.30AM\"\n)\n"
)

我已完成以下替换以删除转义序列

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"
)

但是这个数组应该是这样的

arrConvertedDirNames:(
    Sudha-feb16-2011-02.30PM ,
    Tharanga-jan16-2011-10.30AM
)

如何制作阵列,请任何人帮助我

2 个答案:

答案 0 :(得分:4)

你需要逃避",意思是:

这:replaceOccurrencesOfString:@"""

应该是:replaceOccurrencesOfString:@"\""

答案 1 :(得分:1)

NSCharacterSet *charterSet = [NSCharacterSet characterSetWithCharactersInString:@"""];
stringWithoutCurrentSymbol = [stringWithAnySimbols stringByTrimmingCharactersInSet:charterSet];

小心地返回由从两端删除的新字符串,包含在给定字符集中的接收者字符。