-5

I have a text string with many ",". I would like to replace all "," with an Enter or a linebreak. How can achieve this? Thanks.

  • 4
    quick search brought this up, I think it's what your looking for https://stackoverflow.com/questions/224236/adding-a-newline-into-a-string-in-c-sharp – germas Jul 17 '15 at 00:53
  • 1
    Note: Environment.NewLine is not *always* 'correct'. (Just because it comes up more of then naught; and generally without a disclaimer.) – user2864740 Jul 17 '15 at 01:07
  • For the record, I voted to close this as a duplicate of [this question](https://stackoverflow.com/questions/224236/adding-a-newline-into-a-string-in-c-sharp), not as too broad; Stack Overflow's closing mechanism is broken. – TylerH Jul 20 '15 at 19:26

2 Answers2

1
yourString = yourString.Replace(",", System.Environment.NewLine);

Demo here https://dotnetfiddle.net/M2lBKS

gunr2171
  • 16,104
  • 25
  • 61
  • 88
Shreyas Chavan
  • 1,079
  • 1
  • 7
  • 17
1

There is an example here that talks about the Replace method for strings. Here is an example.

string s = stringwithcomma.Replace(",", System.Environment.NewLine);
J Blaz
  • 783
  • 1
  • 6
  • 26