How to convert this \U202a+98\U00a0910\U00a0280\U00a05305\U202c
to pure string +989102805305
.

- 17,587
- 13
- 87
- 117

- 245
- 1
- 2
- 13
-
what should be your expected value as string.? – Iftikhar Ali Ansari Aug 01 '15 at 09:35
-
http://stackoverflow.com/questions/8001677/how-do-i-convert-a-nsstring-into-a-stdstring – keymusicman Aug 01 '15 at 09:35
-
First tell us where that string came from and how you are getting the values you show (i.e. how are *you* seeing those characters). – trojanfoe Aug 01 '15 at 09:36
-
1you are lucky, it's already a string! – Sulthan Aug 01 '15 at 09:39
-
"+989102805305" this is the perfect string which i want from that string – Asad ali Aug 01 '15 at 09:46
-
1You are turning this into a puzzle. I hate puzzles. If you want help then provide more information. – trojanfoe Aug 01 '15 at 09:47
-
when m retrieving value from sqlite table m getting this value "\U202a+98\U00a0910\U00a0280\U00a05305\U202c" now i want to call this number using tel:// so i have to remove all other character which are in the string, i need this "+989102805305". – Asad ali Aug 01 '15 at 09:51
-
Please update your question and add that you are looking for this phone number. – Michael Dorner Aug 01 '15 at 11:26
-
1@Asadali: You are confusing the actual string that you get, and how NSLog displays it. You will never succeed as a programmer until you learn about Unicode. Especially since quite obviously you are working in an arabic environment (as I can see from the data in your string, not from your name), where understanding Unicode is even more essential than for most people. – gnasher729 Aug 01 '15 at 11:51
2 Answers
NSData *dataenc = [@"\u202a+98\u00a0910\u00a0280\u00a05305\u202c" dataUsingEncoding:NSUTF8StringEncoding];
NSString *encodevalue = [[NSString alloc]initWithData:dataenc encoding:NSUTF8StringEncoding];
NSLog(@"%@", encodevalue); // +98 910 280 5305
NSLog(@"%@", [[encodevalue componentsSeparatedByCharactersInSet:nonAsciiCharacterSet] componentsJoinedByString:@""]); // 989102805305

- 17,587
- 13
- 87
- 117
-
thanx micheal , i got the string, but now am removing space by [encodevalue stringByReplacingOccurrencesOfString:@" " withString:@""] its not removing space, – Asad ali Aug 01 '15 at 13:02
-
`NSLog(@"%@", [[encodevalue componentsSeparatedByCharactersInSet:nonAsciiCharacterSet] componentsJoinedByString:@""]);` But SO is not a coding service! – Michael Dorner Aug 01 '15 at 13:29
-
You seem to be having difficulty understanding the basic idea of what a string is. A string is just an array of characters. The good news in your case is that you already have your array of characters. Now all you need to understand is that is not the end of the story - now you need to store the array of characters into a variable we call a string data type. Your understanding will all clear up with more practice but for right now let me try and help you out. Fortunately there are many ways to turn this into a string data type in iOS. NSString (and NSMutableString) in Cocoa allows you to initialize, format, and append strings with ease.
//You can use the Objective-C literal
NSString *yourStringName = @"\U202a+98\U00a0910\U00a0280\U00a05305\U202c";
//Or you can use the Objective-C format methods
NSString *formatedString = [NSString stringWithFormat:@"My string is %@", yourStringName];
If you NSLog
out is will print My string is \U202a+98\U00a0910\U00a0280\U00a05305\U202c
The new Swift language gives you multiple ways to package an array of characters. In addition to having NSString and all of the factory methods that come along with it, you also have swift's built in String data type. Interestingly enough the swift version of the String class is not really a class, but architected as a swift structure. Learn more about swift classes and structures here.
//The swift (and straight forward) String literal
var yourStringName = "\U202a+98\U00a0910\U00a0280\U00a05305\U202c"
//Or you can use swift's own string interpolation
var interpolatedString = "My string is " + yourStringName
//Also you may still use the NSString methods
var formatedString: NSString = NSString(format: "My string is %@", yourStringName)
Both of these will println()
out My string is \U202a+98\U00a0910\U00a0280\U00a05305\U202c
Either of these avenues you take will allow you to create strings in iOS/MacOSX. I wish you the best of luck in your journey to learn iOS, and well, programming in general.

- 17,587
- 13
- 87
- 117

- 8,153
- 3
- 42
- 77
-
I think this is a string encoding problem, because `\u...` indicates a unicode escape sequence, and not a Swift or `NSString` problem. – Michael Dorner Aug 01 '15 at 11:32
-