Extract partial strings from a TextBox that replace the text of the same TextBox

I need help with my code.
I have a TextBox which contains lines of text like this:

"hello my friends, how r u?","today is good"
"I'm fine","and you"
"have a nice day","thanks"

I want to remove sub-strings using SubString() (or another method, it doesn't matter) for this TextBox items.
I want to see this output in my TextBox (same TextBox, not a new) when I compile my code.

 hello my friends, how r u?
 I'm fine
 have a nice day

1 answer

  • answered 2019-01-11 05:44 Jimi

    Splitting the strings and removing the quotes should be enough, if there aren't any other quotes inside the text.
    After splitting the strings, take the lines in the array that have an even index and put everything back in the TextBox.

    textBox1.Text = string.Join("\r\n", textBox1.Text
                          .Split(new[] { "\r\n", "\",\"" }, StringSplitOptions.RemoveEmptyEntries)
                          .Where((s, i) => i % 2 == 0)).Replace("\"", "");