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,824
  • 17
  • 99
  • 186
Nitish
  • 13,845
  • 28
  • 135
  • 263
  • 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
  • 135,006
  • 31
  • 278
  • 256
1

Identifies last char:

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

Identifies last two chars:

NSString *lastTwoChar = [yourstr substringFromIndex: [yourstr length] - 2];
GAMA
  • 5,958
  • 14
  • 79
  • 126
Krunal
  • 6,440
  • 21
  • 91
  • 155