如何在C#或vb.net中将字符串转换为sbyte数组 [英] How to convert string to sbyte array in c# or vb.net
本文介绍了如何在C#或vb.net中将字符串转换为sbyte数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的开发人员,
有人给我转换代码,用于将字符串值分配给sbyte并存储在sbyte []数组中.在我的代码中,我不使用byte [] array.我只想要sbyte []数组.
Dear Developer,
Anybody give me conversion code for assigning string value to sbyte and store in sbyte[] array.In my code i am not use byte[] array . i want only for sbyte[] array.
推荐答案
这取决于您希望字节表示的编码,但是ASCII版本为:
It depends on the encoding you want the bytes to represent, but the ASCII version would be:
Imports System.Text
.
.
.
Dim chars As Byte() = Encoding.ASCII.GetBytes("Some string")
阅读System.Text.Encoding类,您会发现支持其他编码,例如UTF8,UTF32,Unicode,...以及许多可能对您有用的其他方法.
Read up on the System.Text.Encoding class and you''ll find other encodings are supported, like UTF8, UTF32, Unicode, ... and alot of other methods that may be useful to you.
您可以使用Dave的答案获取字节数组,然后使用常规强制类型转换为sbyte数组:
You can use Dave''s answer to get the byte array and then convert to sbyte array using normal casts:
//get the byte array
byte[] bytes = Encoding.ASCII.GetBytes("Some string");
//convert it to sbyte array
sbyte[] sbytes = new sbyte[bytes.Length];
for (int i = 0; i < bytes.Length; i++)
sbytes[i] = (sbyte)bytes[i];
通过以下链接可能会有所帮助你
此处 [
Go through the below link this may helps you
Here[^]
这篇关于如何在C#或vb.net中将字符串转换为sbyte数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文