0

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

How to do that?

halfer
  • 19,471
  • 17
  • 87
  • 173
Nitish
  • 13,487
  • 26
  • 128
  • 252
  • I guess that a look at `NSString` class reference could help. https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html – Jack Jun 15 '12 at 09:02
  • Try this link may be help you. http://stackoverflow.com/questions/6591538/how-to-capture-last-4-characters-from-nsstring – Dipen Chudasama Jun 15 '12 at 09:05

2 Answers2

3

Use the hasSuffix: method of NSString.

Ole Begemann
  • 134,064
  • 30
  • 273
  • 252
1

Identifies last char:

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

Identifies last two chars:

NSString *lastTwoChar = [yourstr substringFromIndex: [yourstr length] - 2];
GAMA
  • 5,874
  • 13
  • 76
  • 124
Krunal
  • 6,360
  • 20
  • 90
  • 155