I want to replace the substrings 134 and 1254 in a string
((startTime==134)&&(endTime==1254))
with some dynamic value - say, for example, 154 and 1234 respectively.
I have written the code to place using String.Split
method but it seems the code is very long. How can I make it shorter and more robust?
Here is the code:
string s = "((startTime==134)&&(endTime==1254))";
string[] time = s.Split(')').Reverse().ToArray();
var start = time.FirstOrDefault(s => s.Contains("startTime")).Split('=')[2];
var end = time.FirstOrDefault(e => e.Contains("endTime")).Split('=')[2];
start ="154";
end = "1234"
time[3] = "((startTime=="+start;
time[2] = "&&(endTime=="+end;
string joinedstring;
joinedstring= String.Join(")", time.Reverse());
Replace chars in a string using replace method as shown here
string output = input.Replace("old_value", "new_value");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With