gpt4 book ai didi

swift3 - Swift 3 中的 elementsSeparatedByString() 错误

转载 作者:行者123 更新时间:2023-12-02 01:09:40 25 4
gpt4 key购买 nike

var numbers = "Hello,Goodbye,Hi,Bye"
var numbersArr = numbers.componentsSeparatedByString(",")

//["你好"."再见","嗨","再见"]

以上是我正在尝试做的事情的基本表示。我正在尝试使用 componentsSeparatedByString() 将带有逗号的字符串拆分为一个数组,其中数组的每个组件都位于原始字符串的每个逗号之间。

我正在使用 IBM Swift Sandbox(抱歉,我使用的是 Windows :)),在 Swift 3.0 中,我收到此错误消息:

value of type 'String' has no member 'componentsSeparatedByString'

我知道 Swift 3 相当新,这就是为什么我找不到此错误的任何其他引用。

最佳答案

看起来String上有一个components(separatedBy:):

import Foundation

let words = "apple binary cat delta echo".components(separatedBy: " ")
print(words)

enter image description here

IBM Playground 链接: http://swiftlang.ng.bluemix.net/#/repl/57868332b4e4e9971bf9f4e8

关于swift3 - Swift 3 中的 elementsSeparatedByString() 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38358312/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com