我正在从 Twitter 中提取推文并使用它来将其转换为数组:
NSArray *feedData = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&jsonError];
一些推文有大量的新行和空白,为了布局而变得越来越烦人。
我想将任何具有多行的字符串转换为单行字符串。
这是我需要转换的示例字符串:
I used #ECSliding library with my project but i can’t used with
#UITableView plz provide me the way if u know it.
@kbegeman
& thank u ;
正如你所看到的,这个提及有一堆空白和几行额外的行。
我试过用这个:
NSString *tweet = [currentTweet objectForKey:@"text"];
NSString *trimmedTweet = [tweet stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
我也试过这个:
myString = [myString stringByReplacingstringByReplacingOccurrencesOfString:@"\n" withString:@""];
myString = [myString stringByReplacingstringByReplacingOccurrencesOfString:@" " withString:@""];
不幸的是,这不起作用。它与我在 JSON 中阅读的方式有关吗?我用那个方法错了吗?有没有人能想到的其他解决方案?任何帮助都会很棒,谢谢!