Error[8]: Undefined offset: 3, 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(

概述在 Swift中,使用以下字符:“this is a string”,如何获取字符串中存在字符“”(空格)的索引数组? 期望的结果:[4,7,9] 我试过了: let spaces: NSRange = full_string.rangeOfString(" ") 但这只返回4,而不是所有索引. 任何的想法? 这是一个简单的方法: let string = "this is a string" 在 Swift中,使用以下字符串:“this is a string”,如何获取字符串中存在字符“”(空格)的索引数组?

期望的结果:[4,7,9]

我试过了:

let spaces: NSRange = full_string.rangeOfString(" ")

但这只返回4,而不是所有索引.

任何的想法?

解决方法 这是一个简单的方法:

let string = "this is a string"let indices = string    .characters    .enumerate()    .filter { 
let indices = map(filter(enumerate(string),{ [+++].element == " " }),{ [+++].index } )
.element == " " } .map { [+++].index }print(indices) // [4,9]

>字符返回一个CharacterVIEw,它是一个CollectionType(类似于单个字符的数组)
> enumerate将此集合转换为包含索引(0到15)和元素(每个单独的字符)的元组的SequenceType
> filter删除字符不是空格的元组
> map将元组数组转换为仅包含索引的数组

这种方法需要Swift 2(在Xcode 7 beta中).从评论,Swift 1.2语法:

[+++]

(帽子提示到Martin R).

总结

以上是内存溢出为你收集整理的Swift – 在字符串中的多个位置查找字符全部内容,希望文章能够帮你解决Swift – 在字符串中的多个位置查找字符所遇到的程序开发问题。

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

)
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: 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(

概述在 Swift中,使用以下字符:“this is a string”,如何获取字符串中存在字符“”(空格)的索引数组? 期望的结果:[4,7,9] 我试过了: let spaces: NSRange = full_string.rangeOfString(" ") 但这只返回4,而不是所有索引. 任何的想法? 这是一个简单的方法: let string = "this is a string" 在 Swift中,使用以下字符串:“this is a string”,如何获取字符串中存在字符“”(空格)的索引数组?

期望的结果:[4,7,9]

我试过了:

let spaces: NSRange = full_string.rangeOfString(" ")

但这只返回4,而不是所有索引.

任何的想法?

解决方法 这是一个简单的方法:

let string = "this is a string"let indices = string    .characters    .enumerate()    .filter { 
let indices = map(filter(enumerate(string),{ .element == " " }),{ [+++].index } )
.element == " " } .map { [+++].index }print(indices) // [4,9]

>字符返回一个CharacterVIEw,它是一个CollectionType(类似于单个字符的数组)
> enumerate将此集合转换为包含索引(0到15)和元素(每个单独的字符)的元组的SequenceType
> filter删除字符不是空格的元组
> map将元组数组转换为仅包含索引的数组

这种方法需要Swift 2(在Xcode 7 beta中).从评论,Swift 1.2语法:

[+++]

(帽子提示到Martin R).

总结

以上是内存溢出为你收集整理的Swift – 在字符串中的多个位置查找字符全部内容,希望文章能够帮你解决Swift – 在字符串中的多个位置查找字符所遇到的程序开发问题。

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

)
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(

概述在 Swift中,使用以下字符:“this is a string”,如何获取字符串中存在字符“”(空格)的索引数组? 期望的结果:[4,7,9] 我试过了: let spaces: NSRange = full_string.rangeOfString(" ") 但这只返回4,而不是所有索引. 任何的想法? 这是一个简单的方法: let string = "this is a string" 在 Swift中,使用以下字符串:“this is a string”,如何获取字符串中存在字符“”(空格)的索引数组?

期望的结果:[4,7,9]

我试过了:

let spaces: NSRange = full_string.rangeOfString(" ")

但这只返回4,而不是所有索引.

任何的想法?

解决方法 这是一个简单的方法:

let string = "this is a string"let indices = string    .characters    .enumerate()    .filter { 
let indices = map(filter(enumerate(string),{ .element == " " }),{ .index } )
.element == " " } .map { [+++].index }print(indices) // [4,9]

>字符返回一个CharacterVIEw,它是一个CollectionType(类似于单个字符的数组)
> enumerate将此集合转换为包含索引(0到15)和元素(每个单独的字符)的元组的SequenceType
> filter删除字符不是空格的元组
> map将元组数组转换为仅包含索引的数组

这种方法需要Swift 2(在Xcode 7 beta中).从评论,Swift 1.2语法:

[+++]

(帽子提示到Martin R).

总结

以上是内存溢出为你收集整理的Swift – 在字符串中的多个位置查找字符全部内容,希望文章能够帮你解决Swift – 在字符串中的多个位置查找字符所遇到的程序开发问题。

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

)
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: 6, 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(

概述在 Swift中,使用以下字符:“this is a string”,如何获取字符串中存在字符“”(空格)的索引数组? 期望的结果:[4,7,9] 我试过了: let spaces: NSRange = full_string.rangeOfString(" ") 但这只返回4,而不是所有索引. 任何的想法? 这是一个简单的方法: let string = "this is a string" 在 Swift中,使用以下字符串:“this is a string”,如何获取字符串中存在字符“”(空格)的索引数组?

期望的结果:[4,7,9]

我试过了:

let spaces: NSRange = full_string.rangeOfString(" ")

但这只返回4,而不是所有索引.

任何的想法?

解决方法 这是一个简单的方法:

let string = "this is a string"let indices = string    .characters    .enumerate()    .filter { 
let indices = map(filter(enumerate(string),{ .element == " " }),{ .index } )
.element == " " } .map { .index }print(indices) // [4,9]

>字符返回一个CharacterVIEw,它是一个CollectionType(类似于单个字符的数组)
> enumerate将此集合转换为包含索引(0到15)和元素(每个单独的字符)的元组的SequenceType
> filter删除字符不是空格的元组
> map将元组数组转换为仅包含索引的数组

这种方法需要Swift 2(在Xcode 7 beta中).从评论,Swift 1.2语法:

[+++]

(帽子提示到Martin R).

总结

以上是内存溢出为你收集整理的Swift – 在字符串中的多个位置查找字符全部内容,希望文章能够帮你解决Swift – 在字符串中的多个位置查找字符所遇到的程序开发问题。

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

)
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)
Swift – 在字符串中的多个位置查找字符_app_内存溢出

Swift – 在字符串中的多个位置查找字符

Swift – 在字符串中的多个位置查找字符,第1张

概述在 Swift中,使用以下字符:“this is a string”,如何获取字符串中存在字符“”(空格)的索引数组? 期望的结果:[4,7,9] 我试过了: let spaces: NSRange = full_string.rangeOfString(" ") 但这只返回4,而不是所有索引. 任何的想法? 这是一个简单的方法: let string = "this is a string" 在 Swift中,使用以下字符串:“this is a string”,如何获取字符串中存在字符“”(空格)的索引数组?

期望的结果:[4,7,9]

我试过了:

let spaces: NSRange = full_string.rangeOfString(" ")

但这只返回4,而不是所有索引.

任何的想法?

解决方法 这是一个简单的方法:

let string = "this is a string"let indices = string    .characters    .enumerate()    .filter { 
let indices = map(filter(enumerate(string),{ .element == " " }),{ .index } )
.element == " " } .map { .index }print(indices) // [4,9]

>字符返回一个CharacterVIEw,它是一个CollectionType(类似于单个字符的数组)
> enumerate将此集合转换为包含索引(0到15)和元素(每个单独的字符)的元组的SequenceType
> filter删除字符不是空格的元组
> map将元组数组转换为仅包含索引的数组

这种方法需要Swift 2(在Xcode 7 beta中).从评论,Swift 1.2语法:

(帽子提示到Martin R).

总结

以上是内存溢出为你收集整理的Swift – 在字符串中的多个位置查找字符全部内容,希望文章能够帮你解决Swift – 在字符串中的多个位置查找字符所遇到的程序开发问题。

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

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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存