如何在 iPhone 中编码数字代码
我有一些数字代码,我想对“数字代码”进行编码。那么我该如何对字符串进行编码呢?我尝试过 NSASCIIStringEncoding 和 NSUTF8StringEncoding,但它没有对字符串进行编码。所以请帮帮我。
例如:
İ -> İ
ı -> ı
谢谢!
I am having some numerical code and i want to encode the "Numerical Code". So how can i encode the string?. I have tried with NSASCIIStringEncoding and NSUTF8StringEncoding, but it doesn't encoded the string. So please help me out.
Eg :
İ -> İ
ı -> ı
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您拥有的是 Unicode 代码点,而不是字符串。您不需要指定字符串编码,因为您处理的根本不是字符串;而是字符串。他们只是单个角色。从这个意义上讲,NSString 没有“编码”。
要将这些字符放入字符串中,您需要使用:
例如:您不想创建内容为“304”的字符串;那只是一串数字。相反,创建一个值为 304 的 unichar:
“Unichar”只是一个无符号短整型,因此没有指针,也没有引号;您只是将代码点分配给一个数值。将您需要的所有字符捆绑到一个 C 字符串中,并将指针传递给 stringWithCharacters。
What you have are Unicode code points, not strings. You don't need to specify a string encoding, because what you are dealing with aren't strings at all; they're just single characters. And an NSString does not have an "encoding" in this sense.
To get those characters into a string, you need to use:
For example: you don't want to be creating a string with the contents "304"; that's just a string of numbers. Instead, create a unichar with the value of 304:
"Unichar" is just an unsigned short, so no pointer and no quotes; you are just assigning the code point to a numerical value. Bundle all of the characters you need into a C string and pass the pointer to stringWithCharacters.