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

前端 未结 10 1288
耶瑟儿~
耶瑟儿~ 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 12:57

    For Swift 4:

    let myString = "This \n is a st\tri\rng"
    let trimmedString = myString.components(separatedBy: .whitespacesAndNewlines).joined()
    

提交回复
热议问题