5

I'm using Gamekit to send data via bluetooth between two devices. I want to get the name of the device that sent it, but if the name is "Bob's iPhone" I want to cut off the "'s iPhone". I first check for ending in "iPhone" or "iPod Touch".

 if ([name hasSuffix:@" iPhone"]) 
 {
  name = [name substringToIndex:[name length]-7];
 }
 else if ([name hasSuffix:@" iPod Touch"])
 {
  name = [name substringToIndex:[name length]-11];
 }

But when I do the same for "'s" it never returns true. Also the apostrophe looks slightly different then the default apostrophe.

if ([name hasSuffix:@"'s"]) 
{
  name = [name substringToIndex:[name length]-2];
}

Is there some trick to detecting apostrophes? Is there a way I can do this?

EDIT: The apostrophe on the left is what name contains, but is not registering with hasSuffix:@"'s". The apostrophe on the right is the apostrophe I added.

alt text

  • I suppose you should do the same using the escape sequence for the ' I'm not exactly sure but try using escape sequence like \' for capturing the same please confirm me back if this solves your issue. – y ramesh rao Aug 20 '10 at 06:18
  • I did consider the escape sequence, but no luck. (I tried [name hasSuffix:@"\'s"]) – Thegaber777 Aug 20 '10 at 06:23

2 Answers2

1

It might be the case of encoded string. You should make sure the string about this cases

is it 's or is it ´s or is it ‘s or some other character.

You may have some other character that is causing you problems.

These are my guess. Hoping this helps you to find out your problem.

Madhup Singh Yadav
  • 8,110
  • 7
  • 51
  • 84
0

You want the rangeOfString: method in NSString.

if ([name rangeOfString:@"'"].location != NSNotFound)
{
    ...
}
Shaggy Frog
  • 27,575
  • 16
  • 91
  • 128