如何從輸入數字裏面刪除空白:C# - 從輸入號碼刪除空格有INT
1 987年到1987年 - 我需要輸入編號爲int的腳本的其餘部分:
int n = Convert.ToInt32(args.Content);
if (n >= 1000)
n = (int) (n - (n * 0.75));
如何從輸入數字裏面刪除空白:C# - 從輸入號碼刪除空格有INT
1 987年到1987年 - 我需要輸入編號爲int的腳本的其餘部分:
int n = Convert.ToInt32(args.Content);
if (n >= 1000)
n = (int) (n - (n * 0.75));
使用replace(...):
int n = Convert.ToInt32(args.Content.Replace(" ",""));
if (n >= 1000)
n = (int) (n - (n * 0.75));
string numberWithoutSpaces = new Regex(@"\s").Replace("12 34 56", "");
int n = Convert.ToInt32(numberWithoutSpaces);
試試這個:
int n = Convert.ToInt32(args.Content.Replace(" ", string.Empty);
錯誤更正:-)和+1 – 2013-02-11 10:08:30
這是另一種解決方案。
string str = new string(args.Where(c => c != ' ').ToArray());
int n = Convert.ToInt32(str);
替換爲空字符串空間? – 2013-02-11 10:06:21