Nitish
Nitish

Reputation: 14113

NSMutableString check last and second last character

I have a NSMutableString. I need to check whether the last character is @":" or last two characters are @": "

How to do that?

Upvotes: 0

Views: 386

Answers (2)

Krunal
Krunal

Reputation: 6490

Identifies last char:

NSString *lastChar = [yourstr substringFromIndex: [yourstr length] - 1];

Identifies last two chars:

NSString *lastTwoChar = [yourstr substringFromIndex: [yourstr length] - 2];

Upvotes: 1

Ole Begemann
Ole Begemann

Reputation: 135548

Use the hasSuffix: method of NSString.

Upvotes: 3

Related Questions