我希望它像下面的代碼一樣作業,但不是激活字串,而不是第一個整數,而不是第二個,我想在一行中輸入字串整數整數除以空格。
string name = Console.ReadLine();
int numb1 = Convert.ToInt32(Console.ReadLine());
int numb2 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Hi {0}, your number is {1}", name, numb1 numb2);
uj5u.com熱心網友回復:
使用String.Split函式。它將回傳一個字串陣列,然后您可以將其決議為整數。
uj5u.com熱心網友回復:
在加載的字串上使用拆分函式。Split 函式中的引數是字串將被拆分的字符。如果該字符在字串中出現多次,這可能會發生多次。結果是一個字串陣列。
string input = Console.ReadLine(); //"John 65 10"
string[] splitted = input.Split(" ");
string name = splitted[0];
int numb1 = Convert.ToInt32(splitted[1]);
int numb2 = Convert.ToInt32(splitted[2]);
Console.WriteLine("Hi {0}, your number is {1}", name, numb1 numb2);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/336998.html
上一篇:如何將std::string_view轉換為std::string
下一篇:過濾僅包含R中某些字母的字串
