How to check the last char of an NSString

Questions picture Questions · Jul 14, 2010 · Viewed 33.5k times · Source

I want to ask a question about the NSString * in objective C. Can I check the last char of a NSString * object?

Example:

NSString* data = @"abcde,";

if(data is end with ',') // I don't know this part
  // do sth

Answer

user269597 picture user269597 · Jul 14, 2010
NSString *data = @"abcde,";
if([data hasSuffix:@","]) // This returns true in this example
    // do something