/// 统计一个字符的出现次数
let str = "apple banana orange apple banana"
var wordCount:[String: Int] = [:]
for word in str.split(separator: " ") {
wordCount["\(word)", default:0] += 1
}
print(wordCount)
/// 统计一个字符的出现次数
let str = "apple banana orange apple banana"
var wordCount:[String: Int] = [:]
for word in str.split(separator: " ") {
wordCount["\(word)", default:0] += 1
}
print(wordCount)
本文标题:Swift统计String中的单词个数
本文链接:https://www.haomeiwen.com/subject/plxrmqtx.html
网友评论