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.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted Jan 11, 2014, 3:40 AM EST
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.