gpt4 book ai didi

iphone - 如何从 NSString 中删除标题和尾随空格

转载 作者:行者123 更新时间:2023-12-03 18:42:10 25 4
gpt4 key购买 nike

我的 NSString 是这样的:

NSString *myString =  
(
“\n \n 24 K CLUB”,
“\n \n 3 DOLLAR CAFE”,
“\n \n A PEACH OF A PARTY”,
“\n \n A ROYAL AFFAIR CAFE”,
“\n \n AFFAIRS TO REMEMBER CATERERS”,
“\n \n AFRIKAN DELI” )

如何去掉这个换行符和空格,以便我的新字符串如下:新字符串:

(
"24 K CLUB”,
"3 DOLLAR CAFE”,
“A PEACH OF A PARTY”,
“A ROYAL AFFAIR CAFE”,
“AFFAIRS TO REMEMBER CATERERS”,
“AFRIKAN DELI”
)

我尝试过:

myString = [myString stringByReplacingstringByReplacingOccurrencesOfString:@"\n" withString:@""];  
myString = [myString stringByReplacingstringByReplacingOccurrencesOfString:@" " withString:@""];

但没有成功..出现错误:

[__NSArrayI stringByReplacingOccurrencesOfString:withString:]: unrecognized selector sent to instance 0x7062200

最佳答案

怎么样stringByTrimmingCharactersInSet:方法?通过stringByTrimmingCharactersInSet:[NSCharacterSetwhitespaceAndNewlineCharacterSet],可以去除两端的空格和换行符。

关于iphone - 如何从 NSString 中删除标题和尾随空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3800206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com