Chr$ equivalent function in C#

Asked

Viewed 289 times

4

I’m migrating a chunk of code in Visual Basic 6 and came across the following call:

variavel = Chr$(27) & Chr(15)

1 - What would be the equivalent functions in C#?

2 - What is the difference between Chr$ and Chr?

  • 1

    In VB.NET: put the $ at the end of the variable/function explicitly converts its value to a String. How it works with the % for Integer also, & for Double, etc. I don’t know if these other characters work on VB6.

1 answer

3


Just make a cast of the number to char, something like that:

(char)27

But I should probably do something different, the semantics of the language changes so it’s not usually just translating an expression, there must be another way to do this in C#, who knows even in VB6 it was already wrong to do this. One of the reasons I think this is that it makes no sense to use the two forms of function chr(), one that returns String and another that returns Variant.

In C# probably use this:

"\u0027\u0015"

I put in the Github for future reference.

  • 1

    Complementing: the Asc() is the opposite of the operation: (int)'c'.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.