By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,671 Members | 1,350 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,671 IT Pros & Developers. It's quick & easy.

Asc in C#?

P: n/a
Hi there.

VB6 had this function called Asc('a')

So how can i code that function in c#? I want to return
an int.

Regards,
Chua Wen Ching :p
Nov 13 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
Just convert the char to an int

char a = 'a';
int asc = a; // First way
int asc2 = Convert.ToInt32(a); // Second way

Yves

"Chua Wen Ching" <ch**********@chuawenching.com> schreef in bericht
news:06****************************@phx.gbl...
Hi there.

VB6 had this function called Asc('a')

So how can i code that function in c#? I want to return
an int.

Regards,
Chua Wen Ching :p

Nov 13 '05 #2

P: n/a
Phoenix, this was my first response for this problem also, but if you
get into the extended asc values somewhere around 130 + or - 20, there
becomes a very distinct difference in the way that it works. I would
advise pulling in the VisualBasic name space and use the VB.Net asc().
It will work properly for you then.

"phoenix" <pa******@skynetWORK.be> wrote in message news:<#D**************@TK2MSFTNGP10.phx.gbl>...
Just convert the char to an int

char a = 'a';
int asc = a; // First way
int asc2 = Convert.ToInt32(a); // Second way

Yves

"Chua Wen Ching" <ch**********@chuawenching.com> schreef in bericht
news:06****************************@phx.gbl...
Hi there.

VB6 had this function called Asc('a')

So how can i code that function in c#? I want to return
an int.

Regards,
Chua Wen Ching :p

Nov 13 '05 #3

P: n/a
Quizical <Co************@yahoo.com> wrote:
Phoenix, this was my first response for this problem also, but if you
get into the extended asc values somewhere around 130 + or - 20, there
becomes a very distinct difference in the way that it works. I would
advise pulling in the VisualBasic name space and use the VB.Net asc().
It will work properly for you then.


No - it's just a case of working out what you *really* mean. "Asc"
suggests "ASCII" to me, and there *are* no ASCII values about 127.
However, what you *may* actually want is the default system encoding
for a character, in which case using Encoding.Default is the best way
to go.

See http://www.pobox.com/~skeet/csharp/unicode.html for more details.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 13 '05 #4

P: n/a
Use unicode???

But i always thought that unicode is different with ascii!

Thanks for the link.

Regards,
Chua Wen Ching :p
Nov 13 '05 #5

P: n/a
Thanks. The article help me to clear my thoughts.

Regards,
Chua Wen Ching :p
Nov 13 '05 #6

P: n/a
Hi,

Will there be a performance drop if use the VB style Asc
in C#?

And what is AscW() functionality?

Thanks for the replies.

Regards,
Chua Wen Ching :p
Nov 13 '05 #7

P: n/a
"Chua Wen Ching" <ch**********@chuawenching.com> wrote...
Will there be a performance drop if use the VB style Asc
in C#?
Yes, there will, because you will be loading the entire VB compat library,
for the sake of a single function.
And what is AscW() functionality?


It returns the Unicode code point value, rather than Asc (which converts the
Unicode character to the default system code page and returns the code
point's number).
--
MichKa [MS]

This posting is provided "AS IS" with
no warranties, and confers no rights.

Nov 13 '05 #8

P: n/a
The article is indeed wrong -- extended ASCII is a fictional concept, made
up by people/products who do not truly understand what ASCII is.
--
MichKa [MS]

This posting is provided "AS IS" with
no warranties, and confers no rights.
"Mattias Sjögren" <ma********************@mvps.org> wrote in message
news:uS**************@tk2msftngp13.phx.gbl...
Please,Please Don't propagate crap! You get one point for the asc =
ASCII, -10 for bad info and references.


I guess that means you score something like -100 then, because this
article ...

Check out this page as a reference!

http://aspnet.4guysfromrolla.com/art...91802-1.3.aspx

... is pretty bad. You just have to see code like this

char ctmp = (strPwd.Substring((a % intLength),1).ToCharArray()[0]);

to realize that the author doesn't know what he's doing. And I
wouldn't want to use an encryption algorithm implementation that uses
Chr and Asc.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.

Nov 13 '05 #9

P: n/a
Quizical <Co************@yahoo.com> wrote:

<snip>
ASCII, pronounced "ask-key", is the common code for microcomputer
equipment. The standard ASCII character set consists of 128 decimal
numbers ranging from zero through 127 assigned to letters, numbers,
punctuation marks, and the most common special characters. The
Extended ASCII Character Set also consists of 128 decimal numbers and
ranges from 128 through 255 representing additional special,
mathematical, graphic, and foreign characters.

Check out this page as a reference!


Doesn't prove a thing. I'll readily accept that there are many people
out there who believe that the particular 8-bit encoding they prefer is
"the extended ASCII character set" - but many of them will be
different. It's like people saying that something is encoded in "the"
EBCDIC character encoding, when in fact there are many varieties of
that, too.

Just because something is widely believed doesn't mean it's true. Lots
of people have believed in the past (hopefully fewer believe now) that
Java passes objects by reference, for instance - that doesn't make it
true.

Of course, if you could point to an international standards body which
claims that the particular extension you prefer is *the* extended ASCII
character set, that would lend some more credence to your claims.

(Just for reference, the first PC I used came with a rather good
manual, which included *lots* of different code pages in the back.
IIRC, the one which you deem to be "the" extended ASCII table is code
page 437. There are plenty of others, however, and 437 wasn't the
default for all countries.)

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 13 '05 #10

P: n/a
On 13 Jul 2003 15:26:36 -0700, Co************@yahoo.com (Quizical)
wrote:
Jon Skeet <sk***@pobox.com> wrote in message news:<MP************************@news.microsoft.co m>...
Quizical <Co************@yahoo.com> wrote:
> Phoenix, this was my first response for this problem also, but if you
> get into the extended asc values somewhere around 130 + or - 20, there
> becomes a very distinct difference in the way that it works. I would
> advise pulling in the VisualBasic name space and use the VB.Net asc().
> It will work properly for you then.


No - it's just a case of working out what you *really* mean. "Asc"
suggests "ASCII" to me, and there *are* no ASCII values about 127.
However, what you *may* actually want is the default system encoding
for a character, in which case using Encoding.Default is the best way
to go.

See http://www.pobox.com/~skeet/csharp/unicode.html for more details.


Please,Please Don't propagate crap! You get one point for the asc =
ASCII, -10 for bad info and references.

ASCII - The American Standard Code for Information Interchange is a
standard seven-bit code that was proposed by ANSI in 1963, and
finalized in 1968. Other sources also credit much of the work on ASCII
to work done in 1965 by Robert W. Bemer (www.bobbemer.com). ASCII was
established to achieve compatibility between various types of data
processing equipment. Later-day standards that document ASCII include
ISO-14962-1997 and ANSI-X3.4-1986(R1997).


Please take your own advise and don't post/propagate crap.

Your reference to the ASCII standard is correct and defines
codes 0->127 just as Jon Skeet says.

Your other reference is irrelevant, no matter what it says,
because it does not originate from the same standards body.

Oz
Nov 13 '05 #11

P: n/a
> ... is pretty bad. You just have to see code like this

char ctmp = (strPwd.Substring((a % intLength),1).ToCharArray()[0]);

to realize that the author doesn't know what he's doing. And I
wouldn't want to use an encryption algorithm implementation that uses
Chr and Asc.


I'll grant you this, I would not write a line of code that way. Second,
I bet at some point even as an end user you used the RC4 algorithm, that said :P
Nov 13 '05 #12

P: n/a
"Michael \(michka\) Kaplan [MS]" <mi*****@online.microsoft.com> wrote in message news:<uv**************@tk2msftngp13.phx.gbl>...
The article is indeed wrong -- extended ASCII is a fictional concept, made
up by people/products who do not truly understand what ASCII is.
--
MichKa [MS]

fic·tion Pronunciation Key (fkshn) n.

1.) An imaginative creation or a pretense that does not represent
actuality but has been invented.

http://msdn.microsoft.com/library/de...cter_codes.asp

I guess you just posted fic·tion... And you work for microsoft... Are
they fiction too? " people/products who do not truly understand what
ASCII" How do they make M&M's? Why are man holes round? Try those out
tough guy.
Nov 13 '05 #13

P: n/a
Quizical <Co************@yahoo.com> wrote:
fic·tion Pronunciation Key (fkshn) n.

1.) An imaginative creation or a pretense that does not represent
actuality but has been invented.

http://msdn.microsoft.com/library/de...library/en-us/
vclang98/html/_pluslang_ascii_character_codes.asp

I guess you just posted fic·tion... And you work for microsoft... Are
they fiction too? " people/products who do not truly understand what
ASCII" How do they make M&M's? Why are man holes round? Try those out
tough guy.


Yes, MS is wrong on this. It's not the only thing in MSDN that's
incorrect, I'm sure. (I can think of another example immediately,
actually, to do with the singleton pattern implementation in C#.) As I
said before, it's a widespread belief, but that doesn't make it
correct.

Now, if you could post a link to a *standards* document which defines
"extended ASCII" that would be much more convincing.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too
Nov 13 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.