如何将字符串转换为带分隔符的数组? [英] how can I convert string to an array with separator?
本文介绍了如何将字符串转换为带分隔符的数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个以下格式的字符串
I have a string in the following format
myString = "cat+dog+cow"
我需要将每个由+ in分隔的字符串存储到一个数组中。
例如:
I need to store each string separated by + in to a array. Eg:
myArray[0] = cat
myArray[1] = dog
myArray[2] = cow
谁能告诉我正确的方法呢?
Can anyone tell me the proper way to do this?
推荐答案
componentsSeparatedByString:
拆分字符串并将结果返回数组。
componentsSeparatedByString:
splits the string and return the result in an array.
NSArray *myArray = [myString componentsSeparatedByString:@"+"];
[myArray objectAtIndex:0];//cat
[myArray objectAtIndex:1];//dog
[myArray objectAtIndex:2];//cow
这篇关于如何将字符串转换为带分隔符的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文