Hi
I am trying to translate characters encryption logic written in VB to C# language.
In VB, there is Chr() function that converts int/Byte/decimal value to ASCII character
So for integer 65 , it will return A and for 33 it returns
!
But I am facing problem in C# lagnauge for character conversion.
When I try to typecast any decimal value within range 128 -256 to char datatype, my
program is giving output "box"i.e.
Same thing working very fine ibn VB function.
In VB Chr(156) = 'œ'
but in C# (char)(156) = . I an not able to understand why C# is converting like this? Am I missing anything here ?
Did anybody face such kind of issue ? If so, could you please provide your suggestion.
Earliest reply with suggestions will be really appreciated.
Sarang ... what you see depends on how you are using your cast results and also on your culture settings, version of Windows, et cetera ... let me explain with an example:
for (int i = 0; i < 256; i++)
{
Console.WriteLine ("i: {0} ==> [{1}]", i, (char)i);
}
output: "unprintable" characters in my environment show as a box.
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
Edit: (not tested by me) different versions of the .NET Framework
should have similar and likely identical results. end Edit.
Edit # 2:
Sarang, instead of displaying your values ... write them to a file from c# and to a second file from VB.
Your results should be indentical when you compare files, for example with the
fc command.
within computer languages, it should make no difference.
even compilers and development environments, it should make no difference ... for example, i use LINQPad for most of the examples that i create for forums like forums.asp.net.
i'm using win7 on the laptop that i used to create the examples for you above, and also for this reply to you ... if i run my examples on XP and vs2005/vs2008/vs2010/vs2012, i would get identical results.
"en-CA" and "en-US" are sufficiently close such that your results should be close, and likely identical to mine for the following examples:
Console.WriteLine (System.Globalization.CultureInfo.CurrentCulture);
Console.WriteLine ("Control characters 0 to 31");
for (int i = 0; i < 32; i++)
{
Console.Write ((char)i);
}
Console.WriteLine ();
Console.WriteLine ("ASCII characters 32 to 127 ... these are the same for many environments");
for (int i = 32; i < 128; i++)
{
Console.Write ((char)i);
}
Console.WriteLine ();
Console.WriteLine ();
Console.WriteLine ("characters 128 to 255 ... these can be different for many environments");
for (int i = 128; i < 256; i++)
{
Console.Write ((char)i);
}
Console.WriteLine ();
Console.WriteLine (System.Globalization.CultureInfo.CurrentCulture)
Console.WriteLine ("Control characters 0 to 31")
For i as Integer = 0 To 31
Console.Write(Microsoft.VisualBasic.Chr(i))
Next
Console.WriteLine ()
Console.WriteLine ("ASCII characters 32 to 127 ... these are the same for many environments")
For i as Integer = 32 To 127
Console.Write(Microsoft.VisualBasic.Chr(i))
Next
Console.WriteLine ()
Console.WriteLine ("characters 128 to 255 ... these can be different for many environments")
For i as Integer = 128 To 255
Console.Write(Microsoft.VisualBasic.Chr(i))
Next
Console.WriteLine ()
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
The problem is that C# (and VB.net) by default use UTF16, while the old vb6 used a different string encoding.
vb.net kept backward compatability by re-implementing functions similar to those of vb6 and added them to the .net assembly:
Microsoft.VisualBasic , so you can simply add it as a refrence to the C# project and get access to all old vb6 functions.
If you want a cleaner solution, you should see how the function Chr is actually implemented, use a free reflection tool to look at its code.
Sarang ... for the two files you created, are the file sizes approximately the same size in bytes?
N.B.: imho, it's best to examine the files with a text editor that supports
hexadecimal ... for example, the free PSPad text editor (http://www.pspad.com/en/) from Jan Fiala; ... in hexadecimal view, you will see
exactly what was written into your file.
@ sharp11 welcome to forums.asp.net ... glad to see that you are already helping your peers here.)
B-) Please help me by completing my school survey about computer programmers on my website. Thank you!!! Gerry Lowry +1 705-429-7550 wasaga beach, ontario, canada
sarang_for_f...
Member
3 Points
37 Posts
Not able to convert decimal values to ASCII values within range 128-155 in C#
Feb 22, 2013 10:00 AM|LINK
Hi
I am trying to translate characters encryption logic written in VB to C# language.
In VB, there is Chr() function that converts int/Byte/decimal value to ASCII character
So for integer 65 , it will return A and for 33 it returns !
But I am facing problem in C# lagnauge for character conversion.
When I try to typecast any decimal value within range 128 -256 to char datatype, my
program is giving output "box"i.e.
Same thing working very fine ibn VB function.
In VB Chr(156) = 'œ'
but in C# (char)(156) = . I an not able to understand why C# is converting like this? Am I missing anything here ?
Did anybody face such kind of issue ? If so, could you please provide your suggestion.
Earliest reply with suggestions will be really appreciated.
Regards
Sarang
MetalAsp.Net
All-Star
112151 Points
18246 Posts
Moderator
Re: Not able to convert decimal values to ASCII values within range 128-155 in C#
Feb 22, 2013 10:17 AM|LINK
Try using Convert.ToChar() and see if it works.
ashkc
Participant
960 Points
200 Posts
Re: Not able to convert decimal values to ASCII values within range 128-155 in C#
Feb 22, 2013 10:20 AM|LINK
check this
gerrylowry
All-Star
20513 Points
5712 Posts
Re: Not able to convert decimal values to ASCII values within range 128-155 in C#
Feb 22, 2013 10:45 AM|LINK
Edit: on my computer, i get the same result for c# and VB
end Edit.
@ sarang_for_f... welcome to forums.asp.net
Sarang ... what you see depends on how you are using your cast results and also on your culture settings, version of Windows, et cetera ... let me explain with an example:
for (int i = 0; i < 256; i++) { Console.WriteLine ("i: {0} ==> [{1}]", i, (char)i); }output: "unprintable" characters in my environment show as a box.
i: 0 ==> [□] i: 1 ==> [□] i: 2 ==> [□] i: 3 ==> [□] i: 4 ==> [□] i: 5 ==> [□] i: 6 ==> [□] i: 7 ==> [□] i: 8 ==> [□] i: 9 ==> [ ] i: 10 ==> [ ] i: 11 ==> [□] i: 12 ==> [□] i: 13 ==> [ ] i: 14 ==> [□] i: 15 ==> [□] i: 16 ==> [□] i: 17 ==> [□] i: 18 ==> [□] i: 19 ==> [□] i: 20 ==> [□] i: 21 ==> [□] i: 22 ==> [□] i: 23 ==> [□] i: 24 ==> [□] i: 25 ==> [□] i: 26 ==> [□] i: 27 ==> [□] i: 28 ==> [□] i: 29 ==> [□] i: 30 ==> [□] i: 31 ==> [□] i: 32 ==> [ ] i: 33 ==> [!] i: 34 ==> ["] i: 35 ==> [#] i: 36 ==> [$] i: 37 ==> [%] i: 38 ==> [&] i: 39 ==> ['] i: 40 ==> [(] i: 41 ==> [)] i: 42 ==> [*] i: 43 ==> [+] i: 44 ==> [,] i: 45 ==> [-] i: 46 ==> [.] i: 47 ==> [/] i: 48 ==> [0] i: 49 ==> [1] i: 50 ==> [2] i: 51 ==> [3] i: 52 ==> [4] i: 53 ==> [5] i: 54 ==> [6] i: 55 ==> [7] i: 56 ==> [8] i: 57 ==> [9] i: 58 ==> [:] i: 59 ==> [;] i: 60 ==> [<] i: 61 ==> [=] i: 62 ==> [>] i: 63 ==> [?] i: 64 ==> [@] i: 65 ==> [A] i: 66 ==> [B] i: 67 ==> [C] i: 68 ==> [D] i: 69 ==> [E] i: 70 ==> [F] i: 71 ==> [G] i: 72 ==> [H] i: 73 ==> [I] i: 74 ==> [J] i: 75 ==> [K] i: 76 ==> [L] i: 77 ==> [M] i: 78 ==> [N] i: 79 ==> [O] i: 80 ==> [P] i: 81 ==> [Q] i: 82 ==> [R] i: 83 ==> [S] i: 84 ==> [T] i: 85 ==> [U] i: 86 ==> [V] i: 87 ==> [W] i: 88 ==> [X] i: 89 ==> [Y] i: 90 ==> [Z] i: 91 ==> [[] i: 92 ==> [\] i: 93 ==> []] i: 94 ==> [^] i: 95 ==> [_] i: 96 ==> [`] i: 97 ==> [a] i: 98 ==> [b] i: 99 ==> [c] i: 100 ==> [d] i: 101 ==> [e] i: 102 ==> [f] i: 103 ==> [g] i: 104 ==> [h] i: 105 ==> [i] i: 106 ==> [j] i: 107 ==> [k] i: 108 ==> [l] i: 109 ==> [m] i: 110 ==> [n] i: 111 ==> [o] i: 112 ==> [p] i: 113 ==> [q] i: 114 ==> [r] i: 115 ==> [s] i: 116 ==> [t] i: 117 ==> [u] i: 118 ==> [v] i: 119 ==> [w] i: 120 ==> [x] i: 121 ==> [y] i: 122 ==> [z] i: 123 ==> [{] i: 124 ==> [|] i: 125 ==> [}] i: 126 ==> [~] i: 127 ==> [] i: 128 ==> [€] i: 129 ==> [] i: 130 ==> [‚] i: 131 ==> [ƒ] i: 132 ==> [„] i: 133 ==> […] i: 134 ==> [†] i: 135 ==> [‡] i: 136 ==> [ˆ] i: 137 ==> [‰] i: 138 ==> [Š] i: 139 ==> [‹] i: 140 ==> [Œ] i: 141 ==> [] i: 142 ==> [Ž] i: 143 ==> [] i: 144 ==> [] i: 145 ==> [‘] i: 146 ==> [’] i: 147 ==> [“] i: 148 ==> [”] i: 149 ==> [•] i: 150 ==> [–] i: 151 ==> [—] i: 152 ==> [˜] i: 153 ==> [™] i: 154 ==> [š] i: 155 ==> [›] i: 156 ==> [œ] i: 157 ==> [] i: 158 ==> [ž] i: 159 ==> [Ÿ] i: 160 ==> [ ] i: 161 ==> [¡] i: 162 ==> [¢] i: 163 ==> [£] i: 164 ==> [¤] i: 165 ==> [¥] i: 166 ==> [¦] i: 167 ==> [§] i: 168 ==> [¨] i: 169 ==> [©] i: 170 ==> [ª] i: 171 ==> [«] i: 172 ==> [¬] i: 173 ==> [] i: 174 ==> [®] i: 175 ==> [¯] i: 176 ==> [°] i: 177 ==> [±] i: 178 ==> [²] i: 179 ==> [³] i: 180 ==> [´] i: 181 ==> [µ] i: 182 ==> [¶] i: 183 ==> [·] i: 184 ==> [¸] i: 185 ==> [¹] i: 186 ==> [º] i: 187 ==> [»] i: 188 ==> [¼] i: 189 ==> [½] i: 190 ==> [¾] i: 191 ==> [¿] i: 192 ==> [À] i: 193 ==> [Á] i: 194 ==> [Â] i: 195 ==> [Ã] i: 196 ==> [Ä] i: 197 ==> [Å] i: 198 ==> [Æ] i: 199 ==> [Ç] i: 200 ==> [È] i: 201 ==> [É] i: 202 ==> [Ê] i: 203 ==> [Ë] i: 204 ==> [Ì] i: 205 ==> [Í] i: 206 ==> [Î] i: 207 ==> [Ï] i: 208 ==> [Ð] i: 209 ==> [Ñ] i: 210 ==> [Ò] i: 211 ==> [Ó] i: 212 ==> [Ô] i: 213 ==> [Õ] i: 214 ==> [Ö] i: 215 ==> [×] i: 216 ==> [Ø] i: 217 ==> [Ù] i: 218 ==> [Ú] i: 219 ==> [Û] i: 220 ==> [Ü] i: 221 ==> [Ý] i: 222 ==> [Þ] i: 223 ==> [ß] i: 224 ==> [à] i: 225 ==> [á] i: 226 ==> [â] i: 227 ==> [ã] i: 228 ==> [ä] i: 229 ==> [å] i: 230 ==> [æ] i: 231 ==> [ç] i: 232 ==> [è] i: 233 ==> [é] i: 234 ==> [ê] i: 235 ==> [ë] i: 236 ==> [ì] i: 237 ==> [í] i: 238 ==> [î] i: 239 ==> [ï] i: 240 ==> [ð] i: 241 ==> [ñ] i: 242 ==> [ò] i: 243 ==> [ó] i: 244 ==> [ô] i: 245 ==> [õ] i: 246 ==> [ö] i: 247 ==> [÷] i: 248 ==> [ø] i: 249 ==> [ù] i: 250 ==> [ú] i: 251 ==> [û] i: 252 ==> [ü] i: 253 ==> [ý] i: 254 ==> [þ] i: 255 ==> [ÿ]VB
For i as Integer = 0 To 255 Console.WriteLine("i: {0} ==> [{1}]", i, Microsoft.VisualBasic.Chr(i)) NextVB output:
i: 0 ==> [□] i: 1 ==> [□] i: 2 ==> [□] i: 3 ==> [□] i: 4 ==> [□] i: 5 ==> [□] i: 6 ==> [□] i: 7 ==> [□] i: 8 ==> [□] i: 9 ==> [ ] i: 10 ==> [ ] i: 11 ==> [□] i: 12 ==> [□] i: 13 ==> [ ] i: 14 ==> [□] i: 15 ==> [□] i: 16 ==> [□] i: 17 ==> [□] i: 18 ==> [□] i: 19 ==> [□] i: 20 ==> [□] i: 21 ==> [□] i: 22 ==> [□] i: 23 ==> [□] i: 24 ==> [□] i: 25 ==> [□] i: 26 ==> [□] i: 27 ==> [□] i: 28 ==> [□] i: 29 ==> [□] i: 30 ==> [□] i: 31 ==> [□] i: 32 ==> [ ] i: 33 ==> [!] i: 34 ==> ["] i: 35 ==> [#] i: 36 ==> [$] i: 37 ==> [%] i: 38 ==> [&] i: 39 ==> ['] i: 40 ==> [(] i: 41 ==> [)] i: 42 ==> [*] i: 43 ==> [+] i: 44 ==> [,] i: 45 ==> [-] i: 46 ==> [.] i: 47 ==> [/] i: 48 ==> [0] i: 49 ==> [1] i: 50 ==> [2] i: 51 ==> [3] i: 52 ==> [4] i: 53 ==> [5] i: 54 ==> [6] i: 55 ==> [7] i: 56 ==> [8] i: 57 ==> [9] i: 58 ==> [:] i: 59 ==> [;] i: 60 ==> [<] i: 61 ==> [=] i: 62 ==> [>] i: 63 ==> [?] i: 64 ==> [@] i: 65 ==> [A] i: 66 ==> [B] i: 67 ==> [C] i: 68 ==> [D] i: 69 ==> [E] i: 70 ==> [F] i: 71 ==> [G] i: 72 ==> [H] i: 73 ==> [I] i: 74 ==> [J] i: 75 ==> [K] i: 76 ==> [L] i: 77 ==> [M] i: 78 ==> [N] i: 79 ==> [O] i: 80 ==> [P] i: 81 ==> [Q] i: 82 ==> [R] i: 83 ==> [S] i: 84 ==> [T] i: 85 ==> [U] i: 86 ==> [V] i: 87 ==> [W] i: 88 ==> [X] i: 89 ==> [Y] i: 90 ==> [Z] i: 91 ==> [[] i: 92 ==> [\] i: 93 ==> []] i: 94 ==> [^] i: 95 ==> [_] i: 96 ==> [`] i: 97 ==> [a] i: 98 ==> [b] i: 99 ==> [c] i: 100 ==> [d] i: 101 ==> [e] i: 102 ==> [f] i: 103 ==> [g] i: 104 ==> [h] i: 105 ==> [i] i: 106 ==> [j] i: 107 ==> [k] i: 108 ==> [l] i: 109 ==> [m] i: 110 ==> [n] i: 111 ==> [o] i: 112 ==> [p] i: 113 ==> [q] i: 114 ==> [r] i: 115 ==> [s] i: 116 ==> [t] i: 117 ==> [u] i: 118 ==> [v] i: 119 ==> [w] i: 120 ==> [x] i: 121 ==> [y] i: 122 ==> [z] i: 123 ==> [{] i: 124 ==> [|] i: 125 ==> [}] i: 126 ==> [~] i: 127 ==> [] i: 128 ==> [€] i: 129 ==> [] i: 130 ==> [‚] i: 131 ==> [ƒ] i: 132 ==> [„] i: 133 ==> […] i: 134 ==> [†] i: 135 ==> [‡] i: 136 ==> [ˆ] i: 137 ==> [‰] i: 138 ==> [Š] i: 139 ==> [‹] i: 140 ==> [Œ] i: 141 ==> [] i: 142 ==> [Ž] i: 143 ==> [] i: 144 ==> [] i: 145 ==> [‘] i: 146 ==> [’] i: 147 ==> [“] i: 148 ==> [”] i: 149 ==> [•] i: 150 ==> [–] i: 151 ==> [—] i: 152 ==> [˜] i: 153 ==> [™] i: 154 ==> [š] i: 155 ==> [›] i: 156 ==> [œ] i: 157 ==> [] i: 158 ==> [ž] i: 159 ==> [Ÿ] i: 160 ==> [ ] i: 161 ==> [¡] i: 162 ==> [¢] i: 163 ==> [£] i: 164 ==> [¤] i: 165 ==> [¥] i: 166 ==> [¦] i: 167 ==> [§] i: 168 ==> [¨] i: 169 ==> [©] i: 170 ==> [ª] i: 171 ==> [«] i: 172 ==> [¬] i: 173 ==> [] i: 174 ==> [®] i: 175 ==> [¯] i: 176 ==> [°] i: 177 ==> [±] i: 178 ==> [²] i: 179 ==> [³] i: 180 ==> [´] i: 181 ==> [µ] i: 182 ==> [¶] i: 183 ==> [·] i: 184 ==> [¸] i: 185 ==> [¹] i: 186 ==> [º] i: 187 ==> [»] i: 188 ==> [¼] i: 189 ==> [½] i: 190 ==> [¾] i: 191 ==> [¿] i: 192 ==> [À] i: 193 ==> [Á] i: 194 ==> [Â] i: 195 ==> [Ã] i: 196 ==> [Ä] i: 197 ==> [Å] i: 198 ==> [Æ] i: 199 ==> [Ç] i: 200 ==> [È] i: 201 ==> [É] i: 202 ==> [Ê] i: 203 ==> [Ë] i: 204 ==> [Ì] i: 205 ==> [Í] i: 206 ==> [Î] i: 207 ==> [Ï] i: 208 ==> [Ð] i: 209 ==> [Ñ] i: 210 ==> [Ò] i: 211 ==> [Ó] i: 212 ==> [Ô] i: 213 ==> [Õ] i: 214 ==> [Ö] i: 215 ==> [×] i: 216 ==> [Ø] i: 217 ==> [Ù] i: 218 ==> [Ú] i: 219 ==> [Û] i: 220 ==> [Ü] i: 221 ==> [Ý] i: 222 ==> [Þ] i: 223 ==> [ß] i: 224 ==> [à] i: 225 ==> [á] i: 226 ==> [â] i: 227 ==> [ã] i: 228 ==> [ä] i: 229 ==> [å] i: 230 ==> [æ] i: 231 ==> [ç] i: 232 ==> [è] i: 233 ==> [é] i: 234 ==> [ê] i: 235 ==> [ë] i: 236 ==> [ì] i: 237 ==> [í] i: 238 ==> [î] i: 239 ==> [ï] i: 240 ==> [ð] i: 241 ==> [ñ] i: 242 ==> [ò] i: 243 ==> [ó] i: 244 ==> [ô] i: 245 ==> [õ] i: 246 ==> [ö] i: 247 ==> [÷] i: 248 ==> [ø] i: 249 ==> [ù] i: 250 ==> [ú] i: 251 ==> [û] i: 252 ==> [ü] i: 253 ==> [ý] i: 254 ==> [þ] i: 255 ==> [ÿ]one my computer, the results appear to be the same for c# and VB.
perhaps you could tell us more about your code and your environment ... your results should match mine, all other factors being equal.
g.
for me:
result: en-CA
sarang_for_f...
Member
3 Points
37 Posts
Re: Not able to convert decimal values to ASCII values within range 128-155 in C#
Feb 22, 2013 10:55 AM|LINK
Hi Gerry
Thanks for response. For me System.Globalization.CultureInfo.CurrentCulture is "en-US". Does it make differences within languages ?
What I have on my machine is Microsoft Windows XP Professional OS and Microsoft Visual Studio 2010
Could you please suggest what are the other settings I need to check ?
gerrylowry
All-Star
20513 Points
5712 Posts
Re: Not able to convert decimal values to ASCII values within range 128-155 in C#
Feb 22, 2013 11:25 AM|LINK
Edit: (not tested by me) different versions of the .NET Framework
should have similar and likely identical results.
end Edit.
Edit # 2:
Sarang, instead of displaying your values ... write them to a file from c# and to a second file from VB.
Your results should be indentical when you compare files, for example with the fc command.
end Edit # 2.
@ sarang_for_f...
within computer languages, it should make no difference.
even compilers and development environments, it should make no difference ... for example, i use LINQPad for most of the examples that i create for forums like forums.asp.net.
i'm using win7 on the laptop that i used to create the examples for you above, and also for this reply to you ... if i run my examples on XP and vs2005/vs2008/vs2010/vs2012, i would get identical results.
http://msdn.microsoft.com/en-us/library/system.globalization.cultureinfo(v=vs.110).aspx
"CultureInfo Class", .NET 4.5
"en-CA" and "en-US" are sufficiently close such that your results should be close, and likely identical to mine for the following examples:
Console.WriteLine (System.Globalization.CultureInfo.CurrentCulture); Console.WriteLine ("Control characters 0 to 31"); for (int i = 0; i < 32; i++) { Console.Write ((char)i); } Console.WriteLine (); Console.WriteLine ("ASCII characters 32 to 127 ... these are the same for many environments"); for (int i = 32; i < 128; i++) { Console.Write ((char)i); } Console.WriteLine (); Console.WriteLine (); Console.WriteLine ("characters 128 to 255 ... these can be different for many environments"); for (int i = 128; i < 256; i++) { Console.Write ((char)i); } Console.WriteLine ();output:
en-CA Control characters 0 to 31 □□□□□□□□□ □□ □□□□□□□□□□□□□□□□□□ ASCII characters 32 to 127 ... these are the same for many environments !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ characters 128 to 255 ... these can be different for many environments €‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿConsole.WriteLine (System.Globalization.CultureInfo.CurrentCulture) Console.WriteLine ("Control characters 0 to 31") For i as Integer = 0 To 31 Console.Write(Microsoft.VisualBasic.Chr(i)) Next Console.WriteLine () Console.WriteLine ("ASCII characters 32 to 127 ... these are the same for many environments") For i as Integer = 32 To 127 Console.Write(Microsoft.VisualBasic.Chr(i)) Next Console.WriteLine () Console.WriteLine ("characters 128 to 255 ... these can be different for many environments") For i as Integer = 128 To 255 Console.Write(Microsoft.VisualBasic.Chr(i)) Next Console.WriteLine ()VB output:
en-CA Control characters 0 to 31 □□□□□□□□□ □□ □□□□□□□□□□□□□□□□□□ ASCII characters 32 to 127 ... these are the same for many environments !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ characters 128 to 255 ... these can be different for many environments €‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿg.
sarang_for_f...
Member
3 Points
37 Posts
Re: Not able to convert decimal values to ASCII values within range 128-155 in C#
Feb 25, 2013 10:18 AM|LINK
Hi Gerry
I tried in VB as well C#. Still I am getting different results. I am not able to post results here. Getting some site error.
sharp11
Member
18 Points
3 Posts
Re: Not able to convert decimal values to ASCII values within range 128-155 in C#
Feb 25, 2013 02:15 PM|LINK
The problem is that C# (and VB.net) by default use UTF16, while the old vb6 used a different string encoding.
vb.net kept backward compatability by re-implementing functions similar to those of vb6 and added them to the .net assembly: Microsoft.VisualBasic , so you can simply add it as a refrence to the C# project and get access to all old vb6 functions.
If you want a cleaner solution, you should see how the function Chr is actually implemented, use a free reflection tool to look at its code.
gerrylowry
All-Star
20513 Points
5712 Posts
Re: Not able to convert decimal values to ASCII values within range 128-155 in C#
Feb 25, 2013 07:00 PM|LINK
@ sarang_for_f...
are you using vb6 or vb.net? (see the comment by sharp11 at http://forums.asp.net/post/5313533.aspx, above).
Sarang ... for the two files you created, are the file sizes approximately the same size in bytes?
N.B.: imho, it's best to examine the files with a text editor that supports hexadecimal ... for example, the free PSPad text editor (http://www.pspad.com/en/) from Jan Fiala; ... in hexadecimal view, you will see exactly what was written into your file.
@ sharp11 welcome to forums.asp.net ... glad to see that you are already helping your peers here.)