0

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.

5
  • where rose came from? if you put them in another array too you can achieve what you want pretty easy. Commented Dec 23, 2016 at 17:47
  • this means string like subtitle. I just want to change times. words and others must be stay. Commented Dec 23, 2016 at 17:48
  • ok so you should specify in your question that you are trying to change a subtitle file. what format is it? .sub ? Commented Dec 23, 2016 at 17:51
  • i didn't specify so much because i thought my problem not my all code so i didn't want to tire you. I will edit in 2 min. Commented Dec 23, 2016 at 17:54
  • i tried but can't explain myself but thanks you @M.kazemAkhgary Commented Dec 23, 2016 at 18:13

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

That's it. Thanks you so much.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.