LoginSignup
5
5

More than 5 years have passed since last update.

String の hasPrefix, hasSuffix の罠

Posted at
Welcome to Apple Swift version 2.2 (swiftlang-703.0.18.1 clang-703.0.29). Type :help for assistance.
  1> "123".hasPrefix("123")
$R0: Bool = true
  2> "123".hasPrefix("12")
$R1: Bool = true
  3> "123".hasPrefix("1")
$R2: Bool = true
  4> "123".hasPrefix("")
$R3: Bool = false
  5> "123".hasSuffix("")
$R4: Bool = false
  6> "123".hasSuffix("3")
$R5: Bool = true
  7> "123".hasSuffix("23")
$R6: Bool = true
  8> "123".hasSuffix("123")
$R7: Bool = true

これ絶対おかしいだろ……

5
5
5

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
5
5