我不确定,但您可能正在寻找的是获取每个字符的ASCII或Unicode值,然后将它们放入数组或双/整数值列表中。 Unicode(UTF-8)值将始终适合于比双倍效率更高的INT32。 (有关UTF标准的更多信息,请参见“http://en.wikipedia.org/wiki/UTF-8”)。
基本上,那么最简单的C#代码转换为“数字”(字节)的名单将是:
// store the value
string strValue = "";
// alloc enough space for each character to take 4 bytes
// (won't work for large strings but for this it is probably all right)
var resultBytes = new byte[strValue.Length*2];
bool complete; int charsUsed = 0; int bytesUsed = 0;
System.Text.UTF8Encoding.UTF8.GetEncoder().Convert(strValue.ToCharArray(), strValue.Length,
strValue.Length, resultBytes, 0, resultBytes.Length, true, out charsUsed, out bytesUsed, out complete);
// use the byte array as a list of numeric values. Indexes 0 - bytesUsed will be filled
如果我正确地解释原来的问题,这应该完成预期的目标!
你认为价值是什么? “是”根本不是“双重”价值。目前尚不清楚“模拟数字”是什么意思,说实话... –
另外,这与C有什么关系? –
并得出结论:你为什么要这么做? 如果你至少想要一个存储int值的数组来表示字符串的每个字符。 –