我希望能够从输入数组字符串中读取所有数组值,如下所示:
输入字符串
value1,value2
期望输出:
value1,标题类似于'%value2%',
我当前的功能输出所有结果,一次排除,不包括"%' OR TITLE LIKE '%"
。我怎样才能做到这一点?
public static void Main(string[] args)
{
string[] test = { "value1", "value2", "value3" };
string resultString = string.Empty;
Array.ForEach(test, e => resultString += e.Replace(",", "%' OR TITLE LIKE '%"));
Console.WriteLine( "Result is: " + resultString);
Console.ReadLine();
}
}
由于
答案 0 :(得分:1)
这可能是你期待的吗?
public static void Main(string[] args)
{
string[] test = { "value1", "value2", "value3" };
string resultString = string.Empty;
foreach (String s in test)
{
resultString += String.Format("%'{0}'%, ", s);
}
Console.WriteLine(resultString);
Console.ReadLine();
}
它产生的结果是:%'value1'%,%'value2'%,%'value3'%,
答案 1 :(得分:0)
你可以使用Array.IndexOf找到它:
arr[Array.IndexOf(arr, "Value5")] = "value1";
这样的内部循环:
string[] test = { "value1", "value2", "value3" };
string[] test = items.Select(x => x.Replace("value1", "zero")).ToArray();