Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/98.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 没有从字符串中删除空白_Ios_Swift - Fatal编程技术网

Ios 没有从字符串中删除空白

Ios 没有从字符串中删除空白,ios,swift,Ios,Swift,我正在删除带有“trimmingCharacters”的字符串中的空格,但没有删除空格 let number = "123 456" let replaced = number.trimmingCharacters(in: .whitespaces) print(username) print(replaced) 在字符串上使用重放发生(of:with:)方法,即 let number = "123 456" let replaced = number.

我正在删除带有“trimmingCharacters”的字符串中的空格,但没有删除空格


    let number = "123 456"
    let replaced = number.trimmingCharacters(in: .whitespaces)
     print(username)
     print(replaced)


字符串上使用
重放发生(of:with:)
方法,即

let number = "123 456"
let replaced = number.replacingOccurrences(of: " ", with: "")

print(replaced) //Output: 123456

使用字符串重播发生次数

let number = "123 456"
let replaced = number.replacingOccurrences(of: " ", with: "")
print(replaced)

let removed = number.filter{!$0.isWhitespace}
print(removed)
使用过滤器

let removed = number.filter{!$0.isWhitespace}
print(removed)
产出123456