473,378 Members | 1,441 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Asc in C#?

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
13 35229
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
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
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
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
Thanks. The article help me to clear my thoughts.

Regards,
Chua Wen Ching :p
Nov 13 '05 #6
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
"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
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
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
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
> ... 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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: William C. White | last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using cURL? Our website is hosted on a shared drive and the webhost company doesn't installed additional software (such as cURL)...
2
by: Albert Ahtenberg | last post by:
Hello, I don't know if it is only me but I was sure that header("Location:url") redirects the browser instantly to URL, or at least stops the execution of the code. But appearantely it continues...
3
by: James | last post by:
Hi, I have a form with 2 fields. 'A' 'B' The user completes one of the fields and the form is submitted. On the results page I want to run a query, but this will change subject to which...
0
by: Ollivier Robert | last post by:
Hello, I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9 system. The link succeeds but everytime I try to run php, I get a SEGV from inside the libcnltsh.so library. ...
1
by: Richard Galli | last post by:
I want viewers to compare state laws on a single subject. Imagine a three-column table with a drop-down box on the top. A viewer selects a state from the list, and that state's text fills the...
4
by: Albert Ahtenberg | last post by:
Hello, I have two questions. 1. When the user presses the back button and returns to a form he filled the form is reseted. How do I leave there the values he inserted? 2. When the...
1
by: inderjit S Gabrie | last post by:
Hi all Here is the scenerio ...is it possibly to do this... i am getting valid course dates output on to a web which i have designed ....all is okay so far , look at the following web url ...
2
by: Jack | last post by:
Hi All, What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g. select x from y where z=:parameter Which in asp/jsp would be followed by some statements to bind a value...
3
by: Sandwick | last post by:
I am trying to change the size of a drawing so they are all 3x3. the script below is what i was trying to use to cut it in half ... I get errors. I can display the normal picture but not the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.