这是我所拥有的.我的想法是将字符串填充到数组中,对其进行格式化并将其重新转换为字符串.
//input search term
Console.WriteLine("What is your search query?:");
string searchTerm = Console.ReadLine();
//stuff the search term into an array to split it out
string separator = " "; //assumes search terms are separated by spaces
string[] searchTermArray = searchTerm.Split(separator.ToCharArray());
//construct the search term
string searchTermFormat = "";
for (int i = 0; i < searchTermArray.Length; i++)
{
searchTermFormat += searchTermArray[i] + "+";
//Console.WriteLine(searchTermFormat);
}
Run Code Online (Sandbox Code Playgroud)
期望的输出
word1+word2+word3
Run Code Online (Sandbox Code Playgroud)
单词数量不固定的地方.
String.Join("+", searchTermArray)searchTerm.Replace(' ', '+')Uri.EscapeDataString(searchTerm)