How to see if an NSString starts with a certain other string?

后端 未结 5 1752
无人及你
无人及你 2020-12-23 08:51

I am trying to check to see if a string that I am going to use as URL starts with http. The way I am trying to check right now doesn\'t seem to be working. Here is my code:<

5条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-23 09:20

    I like to use this method:

    if ([[temp substringToIndex:4] isEqualToString:@"http"]) {
      //starts with http
    }
    

    or even easier:

    if ([temp hasPrefix:@"http"]) {
        //do your stuff
    }
    

提交回复
热议问题