import Foundation
func getPascalCase(_ input: String) -> String {
var str = input
if !str.contains(" ") {
str = str.replacingOccurrences(of: "(?<=[a-z])(?=[A-Z])", with: " ", options: .regularExpression)
}
let words = str.lowercased().components(separatedBy: CharacterSet.whitespacesAndNewlines.union(CharacterSet(charactersIn: "_")))
var result = ""
for word in words {
if !word.isEmpty {
result += word.capitalized
}
}
return result
}
print(getPascalCase("get file content"))
print(getPascalCase("get_file_content"))
print(getPascalCase("get______file___content"))
print(getPascalCase("get______file____ content"))
print(getPascalCase("GET FILE CONTENT"))
print(getPascalCase("get file content"))
print(getPascalCase("getFileContent"))
/*
run:
GetFileContent
GetFileContent
GetFileContent
GetFileContent
GetFileContent
GetFileContent
GetFileContent
*/