假設有一個字符串「123124125」。 我希望從字符串中取出每3個字符並存儲到整數數組中。將int附加到int []
例如,
int[0] = 123,
int[1] = 124,
int[2] = 125,
下面就讓串密文是 「123124125」:
String^ciphertext;
int length1 = ciphertext-> Length;
int count = 0;
int count1 = 0;
while (count < length1)
{
number[count1] = (ciphertext[count] * 100) + (ciphertext[count+1] * 10) + ciphertext[count+2]);
count = count + 3;
count1++;
}
以上是我寫的代碼。結果應該在number[]
內部爲123,但不是。
當ciphertext[count]
乘以100時,它不會使用「1」乘以100,而是它的十進制數。所以,「1」的十進制是「50」,因此結果是'5000',但不是100.
我的問題是如何將它們3乘3添加到int []中?我怎樣才能避免使用小數,但使用1直?
對不起,我的英語不好。真的很感謝你的幫助,提前致謝。
謝謝大家!!這是工作! 感謝gkovacs90給我建議一種方式,而Jimbo的解釋,現在我完全瞭解它.. 並感謝loxxy建議我另一種方法.. =) –