-1

I have a csv file. It is not so big, the problem is this. The end of the line has these two characters at the end of every line cr lf. Unfortunately in only one single register there is a column with a LF character in the middle. When I try to import the document, this character generates a conflict.

The line looks like this in Notepad++

text1, text2,te(LF)
xt3, text4 (CR LF)

And I need this

text1, text2,text3, text4 (CR LF)

Now, mi question is, how can I delete this character in C# without affecting the end of the row?

Regards

d2907
  • 798
  • 3
  • 15
  • 45

2 Answers2

1

Try this code:

string result = Regex.Replace(text, @"([^\r])\n", "$1");

you simply replace any new line that does not come just after CR with just what comes before it.

Ideone sample

Wapac
  • 4,058
  • 2
  • 20
  • 33
0

Delete all LF. Then replace all CR by CR,LF. Use string.Replace for this.

Graham
  • 799
  • 2
  • 5
  • 14