The string will replace the equivalent for the VB instruction (";" and vbcrlf) in C #

Duplicating a function in C # from some old VB code to perform string manipulation of email text. I'm not sure if this will work in all cases ... can anyone confirm my thoughts on the correct C # code? Are these equivalents?

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; } 
+4
source share
2 answers

Technically, this is not so. 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 usually means "line terminator for the current platform " vbcrlf will always be the Windows CR + LF line terminator no matter what platform this code runs on.

Which one you should use in the long run depends on how this text will be used, and it cannot be adequately deduced from other information in your question.

+5
source

You are using C # escape sequences :

 Clean_Text = Clean_Text.Replace("=\r\n", ""); Clean_Text = Clean_Text.Replace(";\r\n", ""); 
  • \r is an escape sequence for carriage return,
  • \n is the escape sequence for the new line.
0
source

Source: https://habr.com/ru/post/1497837/


All Articles