0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

piazza swift 自分用メモ

Last updated at Posted at 2019-05-16

Stringに含まれるか

var str : String = "hello Swift"

if str.contains("Swift") { // -> true
    print("Swiftが含まれる")
}

if str.contains("swift") { // -> false
    //ここには来ない
}

//大文字小文字を無視させて評価
if str.lowercased().contains("swift") { // -> true
    print("swiftが含まれる")
}

//これも同様にcaseを無視
if str.localizedCaseInsensitiveContains("HELLO"){ // -> true
    print("HELLOが含まれる")
}

paizaにて与えられる値の取り出し

let input_line = readLine()!
let inputHairetu : [String] = input_line.components(separatedBy : " ")

Stringの先頭と後ろの文字の取り出し


let moji = "ABCDEFG"
let prefixMoji = moji.prefix(3) // 先頭3文字の「ABC」
let suffixMoji = moji.suffix(2) // 末尾2文字の「FG」
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?