嗨,
我有以下問題將字符串轉換爲整數:
string str = line.Substring(0,1);
//This picks an integer at offset 0 from string 'line'
所以現在字符串str在其中包含一個整數。我正在做以下幾點:
int i = Convert.ToInt32(str);
我應該打印一個整數,如果我寫下面的語句對嗎?
Console.WriteLine(i);
它編譯沒有任何錯誤,但給出了運行時出現以下錯誤:
型「System.FormatException」未處理的異常出現在mscorlib.dll
其他信息:輸入字符串的不以正確的格式。
請幫忙嗎?
用您正在使用的語言標記它。 – sal 2009-08-20 04:26:27
如果您可以在行變量內提供字符串值,則可能更容易檢測到錯誤。 – rahul 2009-08-20 04:31:15
這是一個重複多次,請參閱http://stackoverflow.com/questions/1019793/how-can-i-convert-string-to-int,http://stackoverflow.com/questions/952469/convert -string-to-int,http://stackoverflow.com/questions/887586/convert-string-to-int。 – 2009-08-20 04:51:17