Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detecting an Apostrophe in a NSString?

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

like image 576
Thegaber777 Avatar asked Nov 15 '22 08:11

Thegaber777


1 Answers

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.

like image 88
Madhup Singh Yadav Avatar answered Dec 05 '22 03:12

Madhup Singh Yadav