0
3

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.

.suffix( )で文字列から指定した文字数分だけ取得

Posted at

#今回の内容

  • .suffix()を使用して、文字列から指定した文字数分だけ取得
  • 例 : abcからbcだけを取得する

#コードと簡単解説

  • .suffix(Int)は、文字列の終わりから1文字目に向けてIntで指定した数値分だけ値を取得します。

    let stringOne = "abcdefg"
    let stringTwo = "1234567"

    override func viewDidLoad() {
        super.viewDidLoad()
      
        print(stringOne.suffix(2))
        print(stringTwo.suffix(5))        
        print(stringTwo.prefix(3).suffix(2))  //prefixで123を取得して、suffixで123から23だけを取得します。
    }
print結果
fg
34567
23

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

0
3
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
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?