Share via


Chr(13) in C#

Question

Thursday, January 6, 2011 7:26 AM

I have a project to convert VB6 codes to C# and I've come across a code which is CHR(13). I though using (char)13 would give me the same result but I'm wrong.

In VB6, using Chr(13) leaves a "^M" (when viewing on a unix environment) in the end of the line, while (char)13 does not. I also used Strings.Chr but to no avail. Anyone here can help me to exactly replicate the output of Chr(13).

BTW, im writing the output of the said function in a file using StreamWriter.

All replies (4)

Thursday, January 6, 2011 7:55 AM ✅Answered

It's - '\r'

It's carriage return...In UNIX it can be displayed in other way...i don't know exactly =).


Thursday, January 6, 2011 7:58 AM ✅Answered

  Sub TestChr13()
    Dim S As String = Chr(13)
  End Sub

    public void TestChr13()
    {
      string S = "\r";
    }


Friday, January 7, 2011 7:07 PM

Thanks guys, '\r' indeed work. Not sure about "^M" in Chr(13) but Writeline procedure of streamwriter also generates "^M", my problem is now solved :D


Friday, January 7, 2011 9:34 PM

That's a notation for Ctrl-M.