views:

48

answers:

2

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

A: 

You want the rangeOfString: method in NSString.

if ([name rangeOfString:@"'"].location != NSNotFound)
{
    ...
}
Shaggy Frog
I tried using rangeOfString, but it still skips over the apostrophe. I think it's an encoded string issue.
Thegaber777
+1  A: 

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
How do I check for the different types of apostrophes?
Thegaber777