Error[8]: Undefined offset: 4, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我知道它的noob问题,我真的在搜索之前搜索.但对于我想知道的内容并没有确切的答案. 我们如何在不使用Objective C的情况下将字符串拆分为数组?例如: var str = "Today is so hot"var arr = str.componentsSeparatedByString(" ") // * >我知道它不起作用,但我正在寻找那样的.我想用“”(或另一个字符串/字符串)拆 我知道它的noob问题,我真的在搜索之前搜索.但对于我想知道的内容并没有确切的答案.
我们如何在不使用Objective C的情况下将字符串拆分为数组?例如:

var str = "Today is so hot"var arr = str.componentsSeparatedByString(" ")  // *

>我知道它不起作用,但我正在寻找那样的.我想用“”(或另一个字符串/字符串)拆分字符串

想法:对我来说可能非常好,扩展了字符串类.但我不知道我是怎么做到的.

编辑:忘记导入基础.如果我导入基础它将工作.但是有没有办法扩展String类?
谢谢

解决方法 如果要按给定字符拆分字符串,则可以使用
内置split()方法,无需基础:

let str = "Today is so hot"let arr = split(str,{ 
let str = "Today is so hot"let arr = split(str,allowEmptySlices: false,isSeparator: { 
let str = "Today is so hot"let arr = str.characters.split(separator: " ").map(String.init)print(arr)
== " "} )println(arr) // [Today,hot]
== " "},maxSplit: Int.max,allowEmptySlices: false)println(arr) // [Today,is,so,hot]

Swift 1.2的更新:使用Swift 1.2(Xcode 6.3)更改参数的顺序,比较split now complains about missing “isSeparator”:

[+++]

Swift 2的更新:见Stuart’s answer.

Swift 3更新:

[+++] 总结

以上是内存溢出为你收集整理的ios – 组件的Swift版本SeparatedByString全部内容,希望文章能够帮你解决ios – 组件的Swift版本SeparatedByString所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 5, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

概述我知道它的noob问题,我真的在搜索之前搜索.但对于我想知道的内容并没有确切的答案. 我们如何在不使用Objective C的情况下将字符串拆分为数组?例如: var str = "Today is so hot"var arr = str.componentsSeparatedByString(" ") // * >我知道它不起作用,但我正在寻找那样的.我想用“”(或另一个字符串/字符串)拆 我知道它的noob问题,我真的在搜索之前搜索.但对于我想知道的内容并没有确切的答案.
我们如何在不使用Objective C的情况下将字符串拆分为数组?例如:

var str = "Today is so hot"var arr = str.componentsSeparatedByString(" ")  // *

>我知道它不起作用,但我正在寻找那样的.我想用“”(或另一个字符串/字符串)拆分字符串

想法:对我来说可能非常好,扩展了字符串类.但我不知道我是怎么做到的.

编辑:忘记导入基础.如果我导入基础它将工作.但是有没有办法扩展String类?
谢谢

解决方法 如果要按给定字符拆分字符串,则可以使用
内置split()方法,无需基础:

let str = "Today is so hot"let arr = split(str,{ 
let str = "Today is so hot"let arr = split(str,allowEmptySlices: false,isSeparator: { 
let str = "Today is so hot"let arr = str.characters.split(separator: " ").map(String.init)print(arr)
== " "} )println(arr) // [Today,hot]
== " "},maxSplit: Int.max,allowEmptySlices: false)println(arr) // [Today,is,so,hot]

Swift 1.2的更新:使用Swift 1.2(Xcode 6.3)更改参数的顺序,比较split now complains about missing “isSeparator”:

Swift 2的更新:见Stuart’s answer.

Swift 3更新:

[+++] 总结

以上是内存溢出为你收集整理的ios – 组件的Swift版本SeparatedByString全部内容,希望文章能够帮你解决ios – 组件的Swift版本SeparatedByString所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
ios – 组件的Swift版本SeparatedByString_app_内存溢出

ios – 组件的Swift版本SeparatedByString

ios – 组件的Swift版本SeparatedByString,第1张

概述我知道它的noob问题,我真的在搜索之前搜索.但对于我想知道的内容并没有确切的答案. 我们如何在不使用Objective C的情况下将字符串拆分为数组?例如: var str = "Today is so hot"var arr = str.componentsSeparatedByString(" ") // * >我知道它不起作用,但我正在寻找那样的.我想用“”(或另一个字符串/字符串)拆 我知道它的noob问题,我真的在搜索之前搜索.但对于我想知道的内容并没有确切的答案.
我们如何在不使用Objective C的情况下将字符串拆分为数组?例如:

var str = "Today is so hot"var arr = str.componentsSeparatedByString(" ")  // *

>我知道它不起作用,但我正在寻找那样的.我想用“”(或另一个字符串/字符串)拆分字符串

想法:对我来说可能非常好,扩展了字符串类.但我不知道我是怎么做到的.

编辑:忘记导入基础.如果我导入基础它将工作.但是有没有办法扩展String类?
谢谢

解决方法 如果要按给定字符拆分字符串,则可以使用
内置split()方法,无需基础:

let str = "Today is so hot"let arr = split(str,{ 
let str = "Today is so hot"let arr = split(str,allowEmptySlices: false,isSeparator: { 
let str = "Today is so hot"let arr = str.characters.split(separator: " ").map(String.init)print(arr)
== " "} )println(arr) // [Today,hot]
== " "},maxSplit: Int.max,allowEmptySlices: false)println(arr) // [Today,is,so,hot]

Swift 1.2的更新:使用Swift 1.2(Xcode 6.3)更改参数的顺序,比较split now complains about missing “isSeparator”:

Swift 2的更新:见Stuart’s answer.

Swift 3更新:

总结

以上是内存溢出为你收集整理的ios – 组件的Swift版本SeparatedByString全部内容,希望文章能够帮你解决ios – 组件的Swift版本SeparatedByString所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1019796.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存