我不確定,但您可能正在尋找的是獲取每個字符的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值的數組來表示字符串的每個字符。 –