gpt4 book ai didi

arrays - 在 if 语句中过滤带有空字符串的字符串,iOS

转载 作者:行者123 更新时间:2023-11-30 11:43:52 25 4
gpt4 key购买 nike

我正在开发自定义键盘。我在过滤字符串数组时遇到问题。我只想在 if 语句中过滤数组,我有一个包含字母和空字符串的数组。我只想在 if 语句中过滤数组,因为我想删除最后一个字符,而不是空字符串。

这是我的代码:

keyboardKeyStr = ["h", "e", "l", "l", "o", " ", "", "t", "h", "i", "s", "", "i", "s", " ", "m", "y", " ", "", "a", "r", "r", "a", "y", " "]

if range.length == 1 && text.count == 0 {
print("Delete Button")

let emptyStr: String? = ""
keyboardKeyStr = keyboardKeyStr.filter {$0 != emptyStr}
keyboardKeyStr.removeLast()
keyboardKeyArr.append(keyboardView.deleteBtn)
self.keyboardKeyStr.append("")
}

最佳答案

试试这个keyboardKeyStr = KeyboardKeyStr.filter{ $0 != ""&& $0 != ""}

关于arrays - 在 if 语句中过滤带有空字符串的字符串,iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49053331/

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