[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework

C# equivelant of VB.NET's Asc

Nathan Sokalski

6/28/2008 1:50:00 AM

VB.NET has a function, Asc(), that gets the Ascii value of a character. I am
attempting to find an equivelant function for C#. Can somebody help me here?
--
Nathan Sokalski
njsokalski@hotmail.com
http://www.nathansok...


57 Answers

=?ISO-8859-1?Q?Arne_Vajh=F8j?=

6/28/2008 1:57:00 AM

0

Nathan Sokalski wrote:
> VB.NET has a function, Asc(), that gets the Ascii value of a character. I am
> attempting to find an equivelant function for C#. Can somebody help me here?

(int)c

Arne

PS: I believe Asc is a VB6'ism.

Mr. Arnold

6/28/2008 5:41:00 AM

0


"Arne Vajhøj" <arne@vajhoej.dk> wrote in message
news:48659a67$0$90274$14726298@news.sunsite.dk...
> Nathan Sokalski wrote:
>> VB.NET has a function, Asc(), that gets the Ascii value of a character. I
>> am attempting to find an equivelant function for C#. Can somebody help me
>> here?
>
> (int)c
>
> Arne
>
> PS: I believe Asc is a VB6'ism.

Asc() can still be used VB.Net. It was in VB3-VB6 and QuickBasic too.

Fred

6/28/2008 5:55:00 AM

0

Dans : news:OSp7aGO2IHA.5512@TK2MSFTNGP06.phx.gbl,
Mr. Arnold écrivait :
> "Arne Vajhøj" <arne@vajhoej.dk> wrote in message
> news:48659a67$0$90274$14726298@news.sunsite.dk...
>> Nathan Sokalski wrote:
>>> VB.NET has a function, Asc(), that gets the Ascii value of a
>>> character. I am attempting to find an equivelant function for C#.
>>> Can somebody help me here?
>>
>> (int)c
>>
>> Arne
>>
>> PS: I believe Asc is a VB6'ism.
>
> Asc() can still be used VB.Net. It was in VB3-VB6 and QuickBasic too.

But it's not equivalent to Arne's solution as it returns windows default
encoding character code (not Unicode value)

--
Fred
foleide@free.fr

Fred

6/28/2008 6:00:00 AM

0

Dans : news:ePaA8NO2IHA.6096@TK2MSFTNGP06.phx.gbl,
Fred écrivait :
> Dans : news:OSp7aGO2IHA.5512@TK2MSFTNGP06.phx.gbl,
> Mr. Arnold écrivait :
>> "Arne Vajhøj" <arne@vajhoej.dk> wrote in message
>> news:48659a67$0$90274$14726298@news.sunsite.dk...
>>> Nathan Sokalski wrote:
>>>> VB.NET has a function, Asc(), that gets the Ascii value of a
>>>> character. I am attempting to find an equivelant function for C#.
>>>> Can somebody help me here?
>>>
>>> (int)c
>>>
>>> Arne
>>>
>>> PS: I believe Asc is a VB6'ism.
>>
>> Asc() can still be used VB.Net. It was in VB3-VB6 and QuickBasic
>> too.
>
> But it's not equivalent to Arne's solution as it returns windows
> default encoding character code (not Unicode value)

PS : Arne's solution is equivalent to AscW

--
Fred
foleide@free.fr

Mr. Arnold

6/28/2008 6:03:00 AM

0


"Fred" <foleide@free.fr.invalid> wrote in message
news:ePaA8NO2IHA.6096@TK2MSFTNGP06.phx.gbl...
> Dans : news:OSp7aGO2IHA.5512@TK2MSFTNGP06.phx.gbl,
> Mr. Arnold écrivait :
>> "Arne Vajhøj" <arne@vajhoej.dk> wrote in message
>> news:48659a67$0$90274$14726298@news.sunsite.dk...
>>> Nathan Sokalski wrote:
>>>> VB.NET has a function, Asc(), that gets the Ascii value of a
>>>> character. I am attempting to find an equivelant function for C#.
>>>> Can somebody help me here?
>>>
>>> (int)c
>>>
>>> Arne
>>>
>>> PS: I believe Asc is a VB6'ism.
>>
>> Asc() can still be used VB.Net. It was in VB3-VB6 and QuickBasic too.
>
> But it's not equivalent to Arne's solution as it returns windows default
> encoding character code (not Unicode value)
>

What does that have to do with anything? It's not a VB6'ism is all that was
being pointed out here and nothing else.

Mr. Arnold

6/28/2008 6:06:00 AM

0


"Fred" <foleide@free.fr.invalid> wrote in message
news:%233qn7QO2IHA.4772@TK2MSFTNGP03.phx.gbl...

<snipped>

Yeah -- yeah don't be going off the deep-end with this.

Fred

6/28/2008 6:22:00 AM

0

Dans : news:%23Lr1ySO2IHA.3756@TK2MSFTNGP04.phx.gbl,
Mr. Arnold écrivait :
> "Fred" <foleide@free.fr.invalid> wrote in message
> news:ePaA8NO2IHA.6096@TK2MSFTNGP06.phx.gbl...
>> Dans : news:OSp7aGO2IHA.5512@TK2MSFTNGP06.phx.gbl,
>> Mr. Arnold écrivait :
>>> "Arne Vajhøj" <arne@vajhoej.dk> wrote in message
>>> news:48659a67$0$90274$14726298@news.sunsite.dk...
>>>> Nathan Sokalski wrote:
>>>>> VB.NET has a function, Asc(), that gets the Ascii value of a
>>>>> character. I am attempting to find an equivelant function for C#.
>>>>> Can somebody help me here?
>>>>
>>>> (int)c
>>>>
>>>> Arne
>>>>
>>>> PS: I believe Asc is a VB6'ism.
>>>
>>> Asc() can still be used VB.Net. It was in VB3-VB6 and QuickBasic
>>> too.
>>
>> But it's not equivalent to Arne's solution as it returns windows
>> default encoding character code (not Unicode value)
>>
>
> What does that have to do with anything? It's not a VB6'ism is all
> that was being pointed out here and nothing else.

I probably misunderstood as english is not my native language. I just
wanted Nathan to know he can get some different results with (int)c that
he used to get with Asc.
I am sorry to disturb.

--
Fred
foleide@free.fr

Michel Posseth [MCP]

6/28/2008 6:52:00 AM

0

'"I believe Asc is a VB6'ism"

It would have been if you needed to set a reference to the
Microsoft.VisualBasic.Compatibility namespace
(Microsoft.VisualBasic.Compatiblity.dll)
please note that if you do not need to set this reference you are working
with the Microsoft.VisualBasic namespace wich is for current Visual Basic
..NET programs , it is a mamanged library that is part of the framework just
as system.data for instance, It is even possible to set a reference to the
VB namespace in C# and thus use all the VB shortcut methods in C#

hth

Michel Posseth
.



"Arne Vajhøj" <arne@vajhoej.dk> schreef in bericht
news:48659a67$0$90274$14726298@news.sunsite.dk...
> Nathan Sokalski wrote:
>> VB.NET has a function, Asc(), that gets the Ascii value of a character. I
>> am attempting to find an equivelant function for C#. Can somebody help me
>> here?
>
> (int)c
>
> Arne
>
> PS: I believe Asc is a VB6'ism.


Cor Ligthert [MVP]

6/28/2008 8:10:00 AM

0

Nathan-

\\int a = Convert.ToInt32('A');
int b = 'A';
///

-Cor

"Nathan Sokalski" <njsokalski@hotmail.com> schreef in bericht
news:%23nV5IFM2IHA.1236@TK2MSFTNGP02.phx.gbl...
> VB.NET has a function, Asc(), that gets the Ascii value of a character. I
> am attempting to find an equivelant function for C#. Can somebody help me
> here?
> --
> Nathan Sokalski
> njsokalski@hotmail.com
> http://www.nathansok...
>

Joergen Bech

6/28/2008 8:18:00 AM

0

On Fri, 27 Jun 2008 21:56:55 -0400, Arne Vajhøj <arne@vajhoej.dk>
wrote:

>Nathan Sokalski wrote:
>> VB.NET has a function, Asc(), that gets the Ascii value of a character. I am
>> attempting to find an equivelant function for C#. Can somebody help me here?
>
>(int)c
>
>Arne
>
>PS: I believe Asc is a VB6'ism.

If you *know* that your character is in the 0x00-0x7f range,
(int)c will do just fine.

But as you can see from using .Net Reflector (below), the full
Asc(char) function is a little more elaborate than that.

Regards,

Joergen Bech

---snip---

public static int Asc(char String)
{
int num;
int num2 = Convert.ToInt32(String);
if (num2 < 0x80)
{
return num2;
}
try
{
byte[] buffer;
Encoding fileIOEncoding = Utils.GetFileIOEncoding();
char[] chars = new char[] { String };
if (fileIOEncoding.IsSingleByte)
{
buffer = new byte[1];
int num3 = fileIOEncoding.GetBytes(chars, 0, 1, buffer,
0);
return buffer[0];
}
buffer = new byte[2];
if (fileIOEncoding.GetBytes(chars, 0, 1, buffer, 0) == 1)
{
return buffer[0];
}
if (BitConverter.IsLittleEndian)
{
byte num4 = buffer[0];
buffer[0] = buffer[1];
buffer[1] = num4;
}
num = BitConverter.ToInt16(buffer, 0);
}
catch (Exception exception)
{
throw exception;
}
return num;
}