I have an string like this:
string s1 = "abc,tom,--Abc, tyu,--ghh";
This string is dynamic, and I need to remove all substrings starting with "--"
.
Output for the example string:
s1 = "abc,tom, tyu";
How can I remove these substrings?
I have an string like this:
string s1 = "abc,tom,--Abc, tyu,--ghh";
This string is dynamic, and I need to remove all substrings starting with "--"
.
Output for the example string:
s1 = "abc,tom, tyu";
How can I remove these substrings?
Look at String.Replace
I am sorry, I should have read the question correctly. Regex comes to mind, for your case.
EDIT
LINQ
string s1 = "abc,tom,--Abc, tyu,--ghh";
var s2 = s1
.Split(',')
.Where(s => s.StartsWith("--") == false)
.Aggregate((start, next) => start + "," + next);
Console.WriteLine(s2);
Try:
Regex.Replace(s1, "--[^,]*,?", "");
This will search the string for blocks that start with --
, have some characters that are not commans (spaces or letter), and the comma (optional - there's no comma in the end).