From webservice iam getting string like this. how to remove unicode symbols and display my string properly.
from : "you don\u2019t have to:"
need to convert like - "you don't have to:"
A workaroud may be:
NSString *srt=[yourString stringByReplacingOccurencesOfString:#"\u2019" withString:#"'"];
Related
I was use the protobuf to read and write config file. but I found the chinese character can't correctly write to the file.
the encode code:
zrd::Config cfg;
zrd::Market *market = nullptr;
market = cfg.add_market();
market->set_id("11");
market->set_name("清江冷链市场");
market->set_district("六合区");
string content;
google::protobuf::TextFormat::PrintToString(cfg, &content);
when run finished , the content is like this:
market {\n id: \"11\"\n name: \"\346\270\205\346\261\237\345\206\267\351\223\276\345\270\202\345\234\272\"\n district: \"\345\205\255\345\220\210\345\214\272\"\n}
why the chinese character is convert to that way ? when I use ofstream to write the content to file, such chinese characters are not convenient to read. but the probobuf can decode it successfully.
I wonder know whether there is way to save the chinese characters in right way?
When I hover over my nsstring in the debugger, apostrophes and special characters show correctly, but when I print the nsstring to the console letters and numbers print fine as before but special characters are scrambled.
I'm creating my string from an array of chars
[code]char utf[10];
string = [NSString stringByAppendingFormat:#"%c",utf[i]";[/code]
If I try to create the string via stringWithUTF8String:&utf[i]; I get an unrecognized selector sent to instance [NSCFConstantString initWitjBytes....
special characters will be printed as UTF string.
I have an image.I have converted this image to NSData and then the NSData to hexadecimal string using byte array.I have then decoded this hexadecimal string to nsnstring using NSUTF8String encoding but it gives me weird string in non readable format .The string displayed is :
IHDR¿”uÓ®iDOTÍ(ÍÈ5·YÛ˙π#IDATxLºsG∂∂y¿∆∆Óu#ÕÃï•$zêAaÇûAÔ)íùDë“H#i43Ú<⁄{o´Ω∑fiìîÓ∑˚7ˆ)Ù˝"6‚DEvuuuUV÷…<Oæ'ˇE˜€®ˆÂàÊ≈®Ó∑q≈RJ≥ñQ,ƒßº˝£ÆG ]∆¨úqèYGL√£Ê °ì4cLËz¬JÏIP"…Ë{"Úø[~ïèöÙ≥ÆG˛°æò˚fi˘ÏGw/<ˆÀû‰ø:qÙ˚äà^P˜⁄eÇ‹ö≤©<Jâ}X‘ËjÖO™ÙH¥>π¡ßx¨¯∂_ˇÀ∞˘â#Æ3áîa»‡óÈ}RùG∆∑∂à3tzØ⁄µö¸zµS1†Î5zµÆòÕ6È‚åÇfiØußùŒîU„UòÉzå≤fl‡”àfl
*[»ËM8≠~É…£’ªTVø…±[=ªœ§∂…ÿiˆÍ\´=h2∏’ˆ∞YH8ÿ™Ï2µCnô¯»z‹ á“.”πïúÕË”ºZk»b ö’ǶOflØÒ®M!£%h¥G,ÊÄI'h]Qó/Â3∏µFAßu®ƒÙõLΩ3lsѨ*´\Ô“8£V_⁄ÌI:C£æ»D–ìrqùæ§ã=‚ùF,ò-l6‘ChÃ/$ùÏ·[w‹nÚlAW%ÓIπbSaÆä∫Ú$‹‚W≥=h·ø|I!:Ú&‹Aœˇ∫#Ç;ʱÜlÊêÕïˆ⁄≤^}⁄•t≥AÀZRµyî±>uï{'=Cs¡°Ÿ¿\px>‘?ÌöHó¬è«ù?§Lè∆O'›}≥æ˛9Ôåóùøåÿ~µ?õpÙL:èZçX˛◊| ü“ˇî2<∑œz{∆Ï√SÇl÷«vp¬’7·Ïüt)ÁÚün9™Y˜éÿz≤VÈîgh‹eXäÀ'}í1A6ÌWŒÖÜg¸O≥ˆÔ"⁄gcˆ˛)˜–¨wp∆√∂w¬˘K ¯8kQ؃±°iüd6†\ä ¬ä≈àl>‘3͉∑œFz«\òt.(nB√sÓHı<1¥z6%
I want to get the text which was there on the image.Is there any way that i can convert the hex string to unicode chars so that i can later on parse it to get the data i want?
Not exactly sure what you're doing, but it sounds like you're trying to convert text in the image itself to a string - something you can't do this way.
Also the string you pasted are for the most part unicode chars.
I have the following NSString:
NSString* searchURL = [NSString stringWithFormat:#"http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20(%22%#%22)%0A%09%09&format=json&env=http%3A%2F%2Fdatatables.org%2Falltables.env&callback=",symbol];
NSLog(#"URL IS: %#", searchURL);
Looks like the %22 is not being included when it is being printed:
URL IS: http://query.yahooapis.com/v1/public/yql?q=select220from2ahoo.finance.quotes2here `º≠ymbol 813020n22#20X1.000982B6P-1042009&format=json&env=http0X1.8CFB8P-1023-1.9907460.000000datatables.org-1.990746alltables.env&callback=
How can I make sure the %22 is included in my string?
If you want to include a "%" sign in a format string use "%%"
Just like in printf et al.
Read the full documentation of stringWithFormat to avoid other bad surprises ...
% is a special character in format strings. Use %% to escape literal percent signs.
% character are used in encoding space in the url formation.If you want to request any url you need to encoding that with stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding
. So the % sign that are appearing are the encoded form of space.So implement accordingly by clearing this fundamental
I have a string here like so:
textbox.text =#"Your name is"
then I want to add right after "your name is" a variable that displays text.
so in Visual Basic I learned it like this:
textbox.text =#"Your name is" & variable1.
But now I can see that it doesn't work like that in Cocoa.
textbox.text = [NSString stringWithFormat:#"Your name is %#", variable1];
Read the documentation for stringWithFormat: to learn about string format specifiers. Basically, you have a format string that contains codes like %#, and the following arguments are put in place of those escape codes.
It has the same syntax as the old C-style printf() function. Cocoa's logging function, NSLog(), also works the same way.
If you need to combine a lot of strings together, try also reading about NSMutableString.
You could also do:
textbox.text = [#"Your name is " stringByAppendingString:variable1];
But if you have to concatenate more than two things, stringWithFormat: is much more concise.
Use NSString's stringByAppendingString: method:
textbox.text = [#"Your name is" stringByAppendingString:variable1];