如何在iOS上将字符串拆分为子字符串? [英] How to split string into substrings on iOS?
本文介绍了如何在iOS上将字符串拆分为子字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从服务器收到了 NSString
。现在我想把它拆分成我需要的子串。
如何分割字符串?
I received an NSString
from the server. Now I want to split it into the substring which I need.
How to split the string?
例如:
substring1:从第二个字符读到第5个字符
substring1:read from the second character to 5th character
substring2:从第6个字符读取10个字符。
substring2:read 10 characters from the 6th character.
推荐答案
您还可以拆分字符串一个子字符串,使用NString的 componentsSeparatedByString 方法。
You can also split a string by a substring, using NString's componentsSeparatedByString method.
文档示例:
NSString *list = @"Norman, Stanley, Fletcher";
NSArray *listItems = [list componentsSeparatedByString:@", "];
这篇关于如何在iOS上将字符串拆分为子字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文