NSXMLParser and the "£" symbol - iphone

Hey all, slight problem when i read in an XML form.
NSXMLParse correctly see's the "£" symbol but its prints out the unicode, \U00a3.
I am just reading it to a string.
[pre_Currency appendString:[self cleanString:string]];
CleanString removes \n - \t and i even added parsing out the unicode and replace it with the Char symbol for the "£".
Oddly enough a NSLog here print a "£" symbol, but when it didEndElement i add it to the dictionary,
[number setObject:[self cleanString:pre_Currency] forKey:#"pre_currency"];
It add it as a unicode Char.
Cant understand why, looking at google theres very little aimed at parsing unicode chars.

I dont know but might be useful to you,if you use the stringByReplacingOccurrencesOfString method
NSString *specialChars=#"YOur string with special characters."
specialChars=[specialChars stringByReplacingOccurrencesOfString:#"\U00a3" withString:#"£"];
Thanks

Yes, it happens for symbols and for other languages fonts in they are not in english, I also got reply here that we will have to decode it as follows:
int c = ... /* your 4 text digit unicode ordinal converted to an integer */
charString = [ NSString stringWithFormat:#"%C", c ];
Original link - How to display Text in Arabic in UIlabel

Related

UITextView right to left Unicode \u202B not working

I am essentially making a teleprompter app and I need a UITextView to display right to left for EVERY line.
NSString *textString = #"Hello There\nMy name is Mark";
textView.text = [#"\u202B" stringByAppendingString: textString];
This is not working. I need this to read
" erehT olleH"
" kraM si eman yM"
I understand that I also need fonts that are upside down etc.. I need to get this part fixed first. Thanks.
The notation \u202b denotes the Unicode character U+202B is RIGHT-TO-LEFT EMBEDDING, which does not affect the writing direction of characters with strong directionality, such as Latin letters.
The character U+202E RIGHT-TO-LEFT OVERRIDE (\u202e) forces right-to-left writing direction, overriding the inherent directionality of characters. To end its effect, use the U+202C POP DIRECTIONAL FORMATTING character:
'\u202eHello There\nMy name is Mark \u202c'
This has little to do with fonts. The rendering engine is supposed to handle some characters like “(” using mirrored symbols, e.g. so that “(foo)” gets rendered as “(oof)” and not “)oof(” in right-to-left writing. But generally, no mirroring is involved; letters remain the same, they just run right to left.
If you actually want to have text mirrored, you need something completely different (a transformation).
This is the logic for reversing the string... I hope this helps you... Just append this string in your textView.text
NSString *sampleString = #"Hello this is sample \n Hello there";
NSMutableString *reverseString = [NSMutableString string];
NSInteger index = [sampleString length];
while (index > 0)
{
index--;
NSRange subStrRange = NSMakeRange(index, 1);
[reverseString appendString:[sampleString substringWithRange:subStrRange]];
}
NSLog(#"%#", reverseString);

is there a way to get the character count in a string? in obj c

hii every one
is there a way to get the character count in a string in obj c?
like how does the SMS app determine how big of a bubble the text view sends and receives? thanks a lot
You can use something like this:
NSString *str = #"Hello World!";
NSUInteger len = str.length;
If it is NSString then use str.length
If it is c string then use strlen(cString)
If it is a NSString then
[string length];
Not sure if you are talking about multi-bytes characters
length
Returns the number of Unicode
characters in the receiver.
- (NSUInteger)length
Return Value
The number of Unicode characters in
the receiver. Discussion
The number returned includes the
individual characters of composed
character sequences, so you cannot use
this method to determine if a string
will be visible when printed or how
long it will appear.
NSLog(#"Length of your string is %d",[yourString length]);

NSString removing single quote in string

This should be simple but it's not working. I am trying to strip single quote marks from an NSString named parms using the following (stripped of non-relevant vars in the format string):
NSString *newVar =[[NSString alloc] initWithFormat:#"%#", [parms stringByReplacingOccurrencesOfString:#"'" withString:#""]];
So if parms contains "Mike's Hat" I would expect that newVar would contain "Mikes Hat". Instead it contains "Mike's Hat".
There must be more to your code than you are proving, but the following works perfectly:
NSString *parms = #"Mike's Hat";
NSString *newVar =[parms stringByReplacingOccurrencesOfString:#"’" withString:#""];
NSLog(#"%#",newVar);
Output: Mikes Hat
There could be a possibility that the character ' may not be the same character in your parms string if the above does not work for you.
Turns out, you are using the wrong character copy/paste this character into your string: ’
Just my two cents on this same problem I had in my code.... When I used the single quote on the keyboard to type ' into my code it didn't work. But I was printing string values to the console. When I copied and pasted the ' character from the console into my code it then worked. What is weird is that I'm using the same key on the keyboard to enter the string into a UITextField so I really don't know why the same key gets turned into something different but that's how I solved it.

convert string to char

I have on one string like #"K_h_10_K_d_10_K_c_13_T_c_13_T_s_13"
I separate them by #"_"
using appCardString=[substringAppCard componentsSeparatedByString:#"_"];
then I have to convert them in to char and want to put in char[] ....
how can I do that ..
please help me ....
It's crashing here
appusedFaces[i]=[[NSString stringWithFormat:#"%#",[appCardString objectAtIndex:i]] charValue];
This will work:
appusedFaces[i]=[[appCardString objectAtIndex:i] characterAtIndex:0];
Though you should add a check that the string has at least one character. You should also be aware that char can only hold character codes up to 255 (unichar can handle any Unicode character).
It also looks like you have some numeric codes in your test string. Checking if the string has more than one character and then calling [[appCardString objectAtIndex:i] intValue] for those characters will handle these.

String encoding of scandinavian letter from url to utf8 to const char on iphone

NSString *theString = #"a %C3%B8 b";
NSLog(#"%#", theString);
NSString *utf8string = [theString stringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding]
NSLog(#"%#", utf8string);
const char *theChar = [utf8string UTF8String];
NSLog(#"%s", theChar);
This logs the following:
'a %C3%B8 b'
'a ø b'
'a √∏ b'
The problem is that I want theChar to be 'a ø b'. Any help on how to achieve that would be greatly appreciated.
I don't think you can. char is a eight bit type so all values are between 0-255. In UTF8 the ø is not encoded in that range.
You might want to look at the unicode type which is a 16 bit type. This can hold the ø as one item and use getCharacters:range: to get the characters out of the NSString
From String Format Specifiers in String Programming Guide:
%s : Null-terminated array of 8-bit
unsigned characters. %s interprets its
input in the system encoding rather
than, for example, UTF-8.
So NSLog(#"%s", theChar) creates and displays NSString object with wrong encoding and theChar itself contains correct string data.
NSLog([NSString stringWithUTF8String:theChar]);
Gives the correct output. (a ø b)
I'd like to add that your theChar does contain the UTF8 byte sequence of your desired string. It's the problem of NSLog("%s") that it can't show the string correctly into the log file and/or the console.
So, if you want to pass the UTF8 byte sequence in char* to some other library, what you did is perfectly correct.