builtin function for string value
strvalues=@"Emp_Name;Emp_ID;23;24;25;26";
contains values like this taking the above string as an inp开发者_如何学Gout the output should be like this
string strresult=@"23;24;25;26";
is there any built in function to do like this
thnaks prince
Let's add a LINQ solution to the lot...
string result = String.Join(";", values.Split(';').Skip(2).ToArray());
Or another possibility
string result = values.Split(new char[] { ';' }, 3)[2];
Both work, but I wouldn't call them elegant either.
string[] values = strvalues.Split(new char[] { ';' });
values will be a string array containing the first column in values[0], second in values[1], etc.
You can use it like this:
for (int i = 2, i < values.Length, i++) {
Console.WriteLine(values[i]);
}
Regex class?
var strresult = new Regex("([0-9]+;?)*").Match(strvalues).Value;
string strresult = strvalues.Replace("Emp_Name;Emp_ID;", "");
How about...
string result = String.Join(";", strvalues.Split(';'), 2, 4);
精彩评论