String replace equivalent for VB statement (";" & vbcrlf) in C#

c#, vbscript

Solution

Technically, they are not. `vbcrlf` is a string constant equal to `"\r\n"` in C#.

`System.Environment.NewLine` is a property that returns `"\r\n"` on Windows systems, but returns `"\n"` on Unix-based systems (Linux and OS X) and more generally means "the line terminator for the current platform." `vbcrlf` will always be the Windows CR+LF line terminator regardless of what platform the code is running on.

Which one you should use ultimately depends on how this text will be used, and this cannot be adequately inferred from other information in your question.

Problem

Duplicating a function in C# from some old VB code to perform string manipulation on email text. I am not sure if this will work in all cases...can anyone confirm my thoughts on the correct C# code to use? Are these equivalent? Original VB: ``` function FixText(Mail_Text) dim Clean_Text Clean_Text = Mail_Text Clean_Text = Replace(Clean_Text, "=" & vbcrlf, "") Clean_Text = Replace(Clean_Text, ";" & vblrcf, "") ` ... other stuff FixText = Clean_Text End Function ``` New C#: ``` public String FixText(Mail_Text) { String Clean_Text = Mail_Text; Clean_Text = Clean_Text.Replace("=" + System.Environment.NewLine, ""); Clean_Text = Clean_Text.Replace(";" + System.Environment.NewLine, ""); // ... other stuff return Clean_Text; } ```

Original source