I’m trying to do some stuff with characterAtIndex and I’m stumped. if ([myString characterAtIndex:0]==0) works fine, if I’m looking for the number zero–but if I’m looking for a decimal point, if ([myString characterAtIndex:0]==.) just gives me an error. Is there another way to do this?
I’m trying to do some stuff with characterAtIndex and I’m stumped. if ([myString characterAtIndex:0]==0)
Share
Check again.
[myString characterAtIndex:0] == 0will compile, but it won’t do what you expect. That condition tests if the first character of your string is the character with the ASCII value of 0, which isn’t the numeral 0: it’s the NUL character.-characterAtIndex:returns a value that you can compare with a character literal, which is a character enclosed in single quotes:'0'or'.', for example.