我正在寻找一个现有的swift2函数来分割空白字符串输入,同时在引用字符串中保留空白。我已阅读stack overflow question 25678373。我的问题似乎并不重复。swift2相当于python的shlex.split来保留引用字符串中的空白
我在cocoapods中搜索了类似的功能。我没有找到它。
如果这个shlex.split函数在swift2中不存在,那么完成类似工作的有效替代方法是什么?在保留内部引用字符串中的空白的同时拆分字符串的另一种方法是什么?
下面是我在蟒蛇的意思是一个例子:
$ python
Python 2.7.6 (default, Jun 22 2015, 18:00:18)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import shlex
>>> input=""" alpha 2 'chicken with teeth' 4 'cat with wings' 6 turkey"""
>>> results = shlex.split(input)
>>> type(results)
<type 'list'>
>>> results[0]
'alpha'
>>> results[2]
'chicken with teeth'
>>> for term in results:
... print(term)
...
alpha
2
chicken with teeth
4
cat with wings
6
turkey
>>>
'我正在寻找一个现有swift2功能[...]'没有这样的功能Swift标准库。 – Moritz
顺便说一下,[shlex.split的源代码](http://scons.org/doc/1.3.1/HTML/scons-api/SCons.compat._scons_shlex-pysrc.html)相当复杂,它使用词法分析器来实现这个任务。 – Moritz