I have a big string array and string like that:
string[] array = new string[3264];
array = {"00:00:45,104","00:01:04,094","01:43:24,001"....};
string str = "00:00:13,614 /n rose /n 00:01:14,001...",
I have same amount of time in string and array. I want to change these values. For example new string must be:
str = "00:00:45,104 /n rose /n 00:01:04,094 ...";
I mean times change for array's element. I think i can find times in string:
var mL = Regex.Matches(subtitle, @"(\d{2}:\d{2}:\d{2},\d+)", RegexOptions.Multiline);
But I don't know how can I change them.
Alexandre Neukirchen
2,7897 gold badges30 silver badges37 bronze badges
1 Answer 1
You can do it with a Regex.Replace, like this:
string[] array = new string[] { "00:00:45,104","00:01:04,094","01:43:24,001"};
string str = "00:00:13,614 /n rose /n 00:01:14,001";
int i = 0;
str = Regex.Replace(str, @"(\d{2}:\d{2}:\d{2},\d+)", m => array[i++]);
The replace takes each match and calls the lambda function to get the string it should be replaced with. So the lambda function is just returning the next value in your array.
answered Dec 23, 2016 at 18:07
gunnerone
3,5722 gold badges16 silver badges19 bronze badges
Sign up to request clarification or add additional context in comments.
1 Comment
Enes
That's it. Thanks you so much.
lang-cs
rosecame from? if you put them in another array too you can achieve what you want pretty easy..sub?