LoginSignup
2
0

More than 3 years have passed since last update.

swiftでString型の変数に任意の文字列が含まれているか確認する

Last updated at Posted at 2019-06-17

String型のcontainsファンクションを使用します。
結果はbooleanで返ってきます。


var str = "含まれてる?"

//含まれる → true
print (str.contains("含"))

//含まれない → false
print (str.contains("ない"))

参考
Apple Developper contains(_:)
https://developer.apple.com/documentation/swift/string/2893238-contains

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