Create a gist now

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Uppercase and lowercase in Swift3
// ----------------------------------------
// String型を使った大文字・小文字変換
// ----------------------------------------
let uppercase:String = "TEST"
print( "大文字→小文字:" + uppercase.lowercased() )
let lowercase:String = "test"
print( "小文字→大文字:" + lowercase.uppercased() )
// ----------------------------------------
// NSString型による大小文字を無視した比較
// ----------------------------------------
import Foundation
let singleByteChar:NSString = "Test" //String型でもOK
if singleByteChar.caseInsensitiveCompare("test") == ComparisonResult.orderedSame {
print("testと一致")
}
//全角文字の比較も可能。
let doubleByteChar:NSString = "TEST"
if doubleByteChar.localizedCaseInsensitiveCompare("test") == ComparisonResult.orderedSame {
print("testと一致")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment