Hi,
some time i faced some problem for replace in a string.
lets assume, i have string "1234gg1234567" and i want to replace "1234" from starting position only OR only from end.
how will i do?
try this code. modify according to you need. This is based on index of a character in a string.
string str = "((startTime==134)&&(endTime==1254))";
int pos_start_1 = str.IndexOf("==") + 2;
int pos_end_1 = str.IndexOf(")&&(");
int pos_start_2 = str.LastIndexOf("==") + 2;
int pos_end_2 = str.IndexOf("))");
string time1 = str.Substring(pos_start_1, (pos_end_1 - pos_start_1));
string time2 = str.Substring(pos_start_2, (pos_end_2 - pos_start_2));
string time1_new = "time1_new";
string time2_new = "time1_new";
string newString = str.Replace(time1, time1_new).Replace(time2, time2_new);