-1

I have a character being entered by the user in a textfield and as per the functionality I have in my code, the system should append the same character at the end of a string. So if the user enters '$', the system adds '$' so I get '$$' on the textfield.

I want get the unicode or ascii value of the '$' character entered by the user. How do I check for it?

tech_human
  • 6,592
  • 16
  • 65
  • 107
  • For all but the most complex Unicode characters: `unichar theChar = [textString characterAtIndex:0]; int theCharIntValue = (int) theChar;`. – Hot Licks Nov 06 '13 at 23:12
  • Sorry if I am being dumb, but is there any difference between unichar and unicode? – tech_human Nov 07 '13 at 00:17
  • "Unicode" is an international character standard. `unichar` is a Cocoa [Touch] data type defined as `unsigned short`. – rmaddy Nov 07 '13 at 00:28
  • BTW - not all Unicode characters can be represented by a single `unichar` variable. Any character with a Unicode value of `\U10000` or greater won't fit in a `unichar`. – rmaddy Nov 07 '13 at 00:32

1 Answers1

0

There is no reason to get the Unicode value of the character for what you are trying to accomplish. Implement the appropriate UITextFieldDelegate method and see if the text ends with $:

if ([someString hasSuffix:@"$"]) {
    // add another dollar sign
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
  • Well I am using the delegate method and inside it I am checking if user entered text = '$' then append string '$'. When I look on the device, both look slightly different to me. The appended string '$' looks little bit thicker/fat than the user entered '$'. I was trying to check unichar's of both of them, but I found them to be same. – tech_human Nov 07 '13 at 01:08
  • If you could think of anything else I need to check or compare for this, then I would appreciate you suggesting. Thanks!! :) – tech_human Nov 07 '13 at 01:09