How to remove punctuation from a string in Swift

1 Answer

0 votes
import Foundation
 
var str = "Swift: is a high-level general-purpose, compiled ~!@#$%^&*() programm[i]ng language."
        
str = str.replacingOccurrences(of: "[\\p{Punct}]", with: "", options: .regularExpression)
        
print(str)
 
 
 
/*
run:
 
Swift is a highlevel generalpurpose compiled ~$^ programming language

*/

 



answered Nov 11, 2024 by avibootz
...