Remove Characters and Everything After from String

后端 未结 2 1039
梦如初夏
梦如初夏 2020-12-31 17:09

I am aware of replacing Strings of a String, but that only works if I know exactly what I want to remove.

If I have a String like the following:

\"hi-there-t

相关标签:
2条回答
  • 2020-12-31 17:56

    Look up pattern-matching, aka regular expressions.

    Oh, wow, TIL there's no built-in way to do regular expressions in an Objective-C Cocoa? according to Regular expressions in an Objective-C Cocoa application

    Anyway, there are libs mentioned in that question.

    0 讨论(0)
  • 2020-12-31 17:57

    It can be done without REGEX like this:

    NSString *string = @"hi-there-this-is-a-test&feature=hi-there";
        NSRange range = [string rangeOfString:@"&feature"];
        NSString *shortString = [string substringToIndex:range.location];
    
    0 讨论(0)
提交回复
热议问题