Convert “???? ??????” in to arabic language

喜欢而已 提交于 2021-01-28 19:24:23

问题


I am getting data from remote sql server like this .

"USER_NAME" = "???? ??????";

I have to get value of username in arabic language but I am getting ??????. I have navchar type of text filed at database. I am using these lines of code:-

NSString *output = [[feed objectForKey:@"USER_NAME"] stringByReplacingPercentEscapesUsingEncoding:NSUnicodeStringEncoding];
                NSLog(@"%@",output);

So How can I fixed this?


回答1:


There can be two possible reasons for sql server to show some unicode data like ????????

Reason 1.
when unicode data wan inserted or updated to that column the user didnt prefix the string with N.

Reason 2.
The Column itself isnt NVARCHAR means it doesnt allow storing unicode characters to be stored.

Example

DECLARE @TABLE TABLE 
(Column1 VARCHAR(100),         --<-- VARCHAR DataType
Column2 NVARCHAR(100),         --<-- NVARCHAR DataType
Column3 NVARCHAR(100)COLLATE  Arabic_CI_AS   --<-- NVARCHAR DataType with specific
)                                               -- arabic collation

INSERT INTO @TABLE VALUES
('هذا هو العربي','هذا هو العربي', 'هذا هو العربي'),    -- Data with out N Prefix
(N'هذا هو العربي',N'هذا هو العربي', N'هذا هو العربي')  -- Data with  N Prefix

SELECT * FROM @TABLE

Result

╔═══════════════╦═══════════════╦═══════════════╗
║    Column1    ║    Column2    ║    Column3    ║
╠═══════════════╬═══════════════╬═══════════════╣
║ ??? ?? ?????? ║ ??? ?? ?????? ║ ??? ?? ?????? ║
║ ??? ?? ?????? ║ هذا هو العربي ║ هذا هو العربي ║
╚═══════════════╩═══════════════╩═══════════════╝

Only data Where Column allows unicode characters to be stored and when I used N prefix will have data stored in the rest are only showing ???????.

In your case you have simply lost the data you cannot possibly convert it back to unicode / Arabic characters . Ouch :S



来源:https://stackoverflow.com/questions/21203330/convert-in-to-arabic-language

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!