0

Why is Chr(130) a comma (,) in Visual Basic 6 but in C# (char)130 is not? (Im not sure what it is, but definitely not a comma!)

Jimbo
  • 22,379
  • 42
  • 117
  • 159
  • A comma is actually `Chr(44)` – Ja͢ck Sep 26 '12 at 13:42
  • 1
    I suggest learning about character encodings. [Joel's article](http://www.joelonsoftware.com/articles/Unicode.html) might be a good jumping-off point. VB6 `Chr` uses "Windows ANSI" encoding - the exact encoding depends on your [Windows code page](http://en.wikipedia.org/wiki/Windows_code_page). Jimbo, I see you're based in Zimbabwe & I don't know what the default Windows code page is for Zimbabwe. C# `(char)` uses 2-byte Windows Unicode characters, Unicode UTF-16. – MarkJ Sep 26 '12 at 16:47

2 Answers2

3

Strictly speaking ASCII is a 7-bit coding, and only defines characters with integer codes 0..127. Manufacturers have often created variant implementations of characters with codes in the range 128..255.

See, for example, the Wikipedia article on ASCII.

High Performance Mark
  • 77,191
  • 7
  • 105
  • 161
  • exactly. ASCII defines characters only the first 128 values of byte. Other 128 values are for each country to define them as they wish. If you want to represent characters other than 128 values of ASCII, use UTF8. – Ivan Kuckir Sep 26 '12 at 13:21
1

Vb Function Chr() is by sure different from the result of casting the integer value 130 to char. To obtain the same result in c# you can set a reference to Microsoft.VisualBasic in your c# and call Microsoft.Visualbasic.Chr(130).

http://msdn.microsoft.com/en-us/library/613dxh46(v=vs.80).aspx

You can also study any of the options exposed in the link below and see the which returns the value you desire.

Int to Char in C#

Community
  • 1
  • 1
Yván Ecarri
  • 1,661
  • 18
  • 39