Hello Buddy ..May Any One Tell Me Pleasse How I Replace That Type Of String After +,-,etc
[S]Select Size/Material=10X14 Plastic - $2.62:6.642
[S]Select Size/Material=10X14 Plastic + $2.62:6.642
[S]Select Size/Material=10X14 Plastic + $2.62:6.642
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Jan 11, 2014, 8:40 AM
using System;
class Test
{
static void Main()
{
string[] sa =
{
"[S]Select Size/Material=10X14 Plastic - $2.62:6.642",
"[S]Select Size/Material=10X14 Plastic + $2.62:6.642",
"[S]Select Size/Material=10X14 Plastic + $2.62:6.642",
};
string replacement = " $3.64:5.523"; // or whatever
char[] separators = {'+', '-'};
foreach(string s in sa)
{
int index = s.IndexOfAny(separators);
string t = s.Substring(0, index + 1) + replacement;
Console.WriteLine(t);
}
Console.ReadKey();
}
}
The output is:
[S]Select Size/Material=10X14 Plastic - $3.64:5.523
[S]Select Size/Material=10X14 Plastic + $3.64:5.523
[S]Select Size/Material=10X14 Plastic + $3.64:5.523
Incidentally, the code assumes there will be only one + or - in the string.
If there could be more than one but you're only interested in the last one, then replace IndexOfAny with LastIndexOfAny.