在 iPhone 应用程序中修剪 Objective C 中的 NSstring 时出现问题

发布于 2024-12-01 07:47:58 字数 2915 浏览 2 评论 0原文

我有一个像“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
)

,可以做些什么来制作数组,所以,请任何人帮助我

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 ,
    Tharanga-jan16-2011-10.30AM
)

what can be done to make array so,, please can any one help me

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

迷荒 2024-12-08 07:47:58

您需要转义 ",意思是:

this: replaceOccurrencesOfString:@"""

应该是: replaceOccurrencesOfString:@"\""

You need to escape the ", meaning:

this: replaceOccurrencesOfString:@"""

should be: replaceOccurrencesOfString:@"\""

清风无影 2024-12-08 07:47:58
NSCharacterSet *charterSet = [NSCharacterSet characterSetWithCharactersInString:@"""];
stringWithoutCurrentSymbol = [stringWithAnySimbols stringByTrimmingCharactersInSet:charterSet];

返回一个新字符串,该字符串是通过从两端删除给定字符集中包含的接收者字符而得到的。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文