简体   繁体   English

使用Swift的String的ASCII编码

[英]ASCII encoding for String using Swift

What I need to do is Convert a String to byte array with ASCII encoding… I'm using Swift and I can see the utf-8, utf-16 and unicodeScalars but no Ascii encoding found for String. 我需要做的是使用ASCII编码将字符串转换为字节数组……我使用的是Swift,我可以看到utf-8,utf-16和unicodeScalars,但是找不到String的Ascii编码。

How can I do it? 我该怎么做? For example for a string like “ID00000004” the content of the bytes should be “49443030303030303034” 例如,对于类似“ ID00000004”的字符串,字节的内容应为“ 49443030303030303034”

Can you help me? 你能帮助我吗? Thanks in advance 提前致谢

the following code is correct, the result was printed in console in decimal instead of hex 以下代码正确,结果在控制台中以十进制而不是十六进制打印

var result : [Byte] = UInt8 var结果:[字节] = UInt8

Thank you 谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM