-1

I have this code:

Dim sCenter As String
sCenter = Chr(27) + Chr(97) + Chr(1)

And I'm trying to convert to a C# code. Online converters always fail to convert... :(

So, what is the C# equivalente of Chr(number)?

Maybe Char.ConvertFromUtf32(10);

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Nicke Manarin
  • 3,026
  • 4
  • 37
  • 79
  • 2
    similar question asked/answered here: http://stackoverflow.com/questions/721201/whats-the-equivalent-of-vbs-asc-and-chr-functions-in-c – applesElmi Nov 17 '14 at 19:10
  • http://stackoverflow.com/questions/4648781/how-to-get-character-for-a-given-ascii-value – hunch_hunch Nov 17 '14 at 19:10
  • Actually, one of the deleted answers was very close: Soner Gonul wrote string sCenter; sCenter = (char)27 + (char)97 + (char)1; Which doesn't work because a `char` is still basically an integer, so that just yields 125. However, if you add a `char` to a `string`, C# works properly , hence: `sCenter = "" + (char)27 + (char)97 + (char)1;` – James Curran Nov 17 '14 at 19:39
  • @JamesCurran Yeah, I realized that after I post and that's why I deleted. I undeleted my answer based your suggestion if you don't mind :) – Soner Gönül Nov 17 '14 at 20:20
  • See a complete answer: [C# Char from Int used as String - the real equivalent of VB Chr()](http://stackoverflow.com/questions/36976240/c-sharp-char-from-int-used-as-string-the-real-equivalent-of-vb-chr) – ib11 Jul 09 '16 at 06:44
  • [What's the equivalent of VB's Asc() and Chr() functions in C#?](https://stackoverflow.com/q/721201/608639). – jww Feb 23 '19 at 08:57

1 Answers1

21

Feel like taking risk to answer but how about?

string sCenter;
sCenter = "" + (char)27 + (char)97 + (char)1;

Thanks to James Curran's comment about char integral addition. As his suggested, I added meaningless "" with char to get string + char which uses .ToString() with String.Concat method at background.

Community
  • 1
  • 1
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364