How to remove all the spaces and \n\r in a String?

前端 未结 10 1285
耶瑟儿~
耶瑟儿~ 2020-12-28 12:44

What is the most efficient way to remove all the spaces, \\n and \\r in a String in Swift?

I have tried:

for character in s         


        
10条回答
  •  渐次进展
    2020-12-28 13:12

    Swift 4:

    let string = "Test\n with an st\tri\rng"
    print(string.components(separatedBy: .whitespacesAndNewlines))
    // Result: "Test with an string"
    

提交回复
热议问题