在 iPhone 应用程序中修剪 Objective C 中的 NSstring 时出现问题
我有一个像“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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要转义
"
,意思是:this:
replaceOccurrencesOfString:@"""
应该是:
replaceOccurrencesOfString:@"\""
You need to escape the
"
, meaning:this:
replaceOccurrencesOfString:@"""
should be:
replaceOccurrencesOfString:@"\""
返回一个新字符串,该字符串是通过从两端删除给定字符集中包含的接收者字符而得到的。
be carefully Returns a new string made by removing from both ends of the receiver characters contained in a given character set.