Regex_For removing new line

Hi ,

I have a string as folows :
October13,1930-
May18,2022

I want output as :
October13,1930-May18,2022

Thanks

You can try the following:

var_YourStringVariable.Replace(Environment.NewLine,String.Empty)

This should remove all “NewLines” and leave everything in a single line.

Best Regards,
Ignasi

Hi Ignasi,

I have tried that but the output is same. No change.

Thanks.

Hi,

Can you try the following expression?

System.Text.RegularExpressions.Regex.Replace(yourString,"\r?\n","")

Regards,

1 Like

Thanks It worked. But what does \? means… If I may ask you.

1 Like

Hi,

Thanks It worked. But what does ? means… If I may ask you.

There are some type of linebreak : windows style is CR+LF (\r\n) , unix style is LF (\n).
The above is regex and the pattern “\r?\n” means one or none \r and one \n. As a result, this pattern matches both style line break.

If we know linebreak is unix style : LF, in the string, it might also work stringVar.Replace(vbLf,"")

Regards,

1 Like

Thank you it helped.

1 Like