[英]Swift-Turn String into Array, but not a character array
Currently I am trying to convert this String: "['bob','joe','tom']" into a proper array: ['bob','joe','tom'] Is there a built in method to do this?目前我正在尝试将此字符串:“['bob','joe','tom']”转换为适当的数组:['bob','joe','tom'] 是否有内置方法这个? If not what should I do.
如果不是我该怎么办。
Use This solution使用此解决方案
str.removeFirst() // Remove '[' and return 'bob','joe','tom']
str.removeLast() // Remove ']' and return 'bob','joe','tom'
str = str.replacingOccurrences(of: "'", with: "") // Remove ' and return bob,joe,tom
var arr = str.components(separatedBy: ",") // Split by , and convert string into array
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.