Objective-C (cocoa) equivalent to python's endswith/beginswith

后端 未结 3 1706
遇见更好的自我
遇见更好的自我 2021-01-17 09:37

Python has string.startswith() and string.endswith() functions which are pretty useful. What NSString methods can I use to have the same function?<

3条回答
  •  遥遥无期
    2021-01-17 10:10

    Use -hasPrefix: and -hasSuffix::

    NSString *s = @"foobar";
    NSLog(@"%d %d\n", [s hasPrefix:@"foo"], [s hasSuffix:@"bar"]);
    // Output: "1 1"
    

提交回复
热议问题