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 3 years have passed since last update.

Stringが使えるメソッド(今日使用した4つ)

Posted at

今回の内容

  • 今日、使用したStringが使用できるメソッドについて

コードと簡単解説

  • まずは、メソッドを使うために変数(String型)を宣言しておきます。
    var uppercasedString = "abcdefg"
    var lowercasedString = "ABCDEFG"
    var containString = "0123456789"
    var replacingOccurrencesString = "1111111"

小文字の値を大文字に変換

    print(uppercasedString.uppercased())
Print結果
    ABCDEFG

大文字の値を小文字に変換

    print(lowercasedString.lowercased())
Print結果
    abcdefg

特定の値が含まれてるかを判定する

  • Bool値で結果を判定します
    print(containString.contains("0"))
Print結果
    true

特定の値を希望の値に変更

  • .replacingOccurrences(of: "1", with: "2")は、1の値を全て2に変更しています。
    print(replacingOccurrencesString.replacingOccurrences(of: "1", with: "2"))
Print結果
    2222222

終わり

ご指摘、ご質問などありましたら、コメントまでお願い致します。

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?