Asc in C#?

C

Chua Wen Ching

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
 
P

phoenix

Just convert the char to an int

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

Yves
 
Q

Quizical

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.
 
J

Jon Skeet

Quizical said:
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.
 
C

Chua Wen Ching

Use unicode???

But i always thought that unicode is different with ascii!

Thanks for the link.

Regards,
Chua Wen Ching :p
 
C

Chua Wen Ching

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
 
M

Michael \(michka\) Kaplan [MS]

Chua Wen Ching said:
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).
 
M

Michael \(michka\) Kaplan [MS]

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 said:
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 ...



... 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
 
J

Jon Skeet

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.)
 
O

ozbear

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
 
Q

Quizical

... 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
 
Q

Quizical

Michael \(michka\) Kaplan said:
The article is indeed wrong -- extended ASCII is a fictional concept, made
up by people/products who do not truly understand what ASCII is.
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/d...ng98/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.
 
J

Jon Skeet

Quizical said:
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/default.asp?url=/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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top