我有這樣的代碼,但是,但是當我運行該程序給了我這個錯誤System.FormatException:輸入字符串的不正確的格式」。異常轉換ToInt32丹斯C#
public static void Main(string[] args)
{
string a =TextFormater("Teste teste ");
Console.WriteLine(a);
}
public static string TextFormater(string ChaineTextArea)
{
string val = string.Empty;
string Valreturn = string.Empty;
int result;
for (int i = 0; i <= ChaineTextArea.Length; i++)
{
val = ChaineTextArea.Substring(i, 1);
var chars = val.ToCharArray();
result = Convert.ToInt32(val);
if (result != 13)
{
Valreturn= val;
}
else
{
Valreturn= "<br>" + val;
}
}
return Valreturn;
}
錯誤有效的格式:System.FormatException:輸入字符串的不正確的格式。 at System.Number.StringToNumber(String str,NumberStyles options,NumberBuffer&number,NumberFormatInfo info,Boolean parseDecimal) at System.Number.ParseInt32(String s,NumberStyles style,NumberFormatInfo info) at System.Convert.ToInt32(String value ) at Rextester.Program.TextFormater(String ChaineTextArea) at Rextester.Program.Main(String [] args) – Narjis
你認爲什麼「Teste teste」是數字? –
嘗試將字母轉換爲數字? – Sujith