473,320 Members | 2,029 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,320 software developers and data experts.

What is the JavaScript equivalents for Chr() and Asc() (from BASIC)

Hi Gang,

I would like to use a caesar cipher on the mailto: links in my website
to prevent crawlers from farming the e-mails off my site. Can someone
tell me the equivalents to Chr() and Asc() from Visual Basic, but for
JavaScript? Chr(n) returns the character based on the numeric ASCII
code. For example
Chr(34) --> "
Asc(") --> 34

Thanks,
Christian Blackburn

Jun 14 '06 #1
5 148950

Christian Blackburn wrote:

[snip]
Chr(34) --> " [/snip]

String.fromCharCode
e.g.

var sChar=String.fromCharCode(34);

[snip] Asc(") --> 34

[/snip]

charCodeAt(nIndex) returns the char code for the character at a given
index position within a string (zero based index).

Thus if you want the code for a single character:-

var nCharCode="\"".charCodeAt(0);

See
<URL:http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Objects:String:charC odeAt>

Regards

Julian

Jun 14 '06 #2
Christian Blackburn wrote on 14 jun 2006 in comp.lang.javascript:
I would like to use a caesar cipher on the mailto: links in my website
to prevent crawlers from farming the e-mails off my site. Can someone
tell me the equivalents to Chr() and Asc() from Visual Basic, but for
JavaScript? Chr(n) returns the character based on the numeric ASCII
code. For example
Chr(34) --> "
Asc(") --> 34


This is realy something you should be able to look up in the specs.

<http://msdn.microsoft.com/library/en-us/dnanchor/html/scriptinga.asp>

Or the ECMA equivalent.

===============

These are not equivalent, as their use is much more versatile:

var test = String.fromCharCode(34);

var test = '"'.charCodeAt(0)


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jun 14 '06 #3
Hi Julian,

Thank you so much for your help and the examples. I really appreciate
it.

Cheers,
Christian Blackburn

Jun 14 '06 #4
Hi Evertjan,

Thanks for sending me the JScript Help URL. I may reference that from
time to time, but in general I prefer to use Netscape's JavaScript for
compatibility reasons. I'll agree that the command is more versatile.
However, for my purposes it's more or less the same :).

Cheers,
Christian Blackburn

Evertjan. wrote:
Christian Blackburn wrote on 14 jun 2006 in comp.lang.javascript:
I would like to use a caesar cipher on the mailto: links in my website
to prevent crawlers from farming the e-mails off my site. Can someone
tell me the equivalents to Chr() and Asc() from Visual Basic, but for
JavaScript? Chr(n) returns the character based on the numeric ASCII
code. For example
Chr(34) --> "
Asc(") --> 34


This is realy something you should be able to look up in the specs.

<http://msdn.microsoft.com/library/en-us/dnanchor/html/scriptinga.asp>

Or the ECMA equivalent.

===============

These are not equivalent, as their use is much more versatile:

var test = String.fromCharCode(34);

var test = '"'.charCodeAt(0)


--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)


Jun 14 '06 #5
JRS: In article <11**********************@c74g2000cwc.googlegroups .com>
, dated Tue, 13 Jun 2006 23:26:09 remote, seen in
news:comp.lang.javascript, Christian Blackburn <christian.Blackburn@Yaho
o.com> posted :
Hi Gang,

I would like to use a caesar cipher on the mailto: links in my website
to prevent crawlers from farming the e-mails off my site. Can someone
tell me the equivalents to Chr() and Asc() from Visual Basic, but for
JavaScript? Chr(n) returns the character based on the numeric ASCII
code. For example
Chr(34) --> "
Asc(") --> 34


The following, from <URL:http://www.merlyn.demon.co.uk/problems.htm>,
implements a specific Caesar cipher.

function R13(A) {
if (A> 96 && A<110) return A+13
if (A>109 && A<123) return A-13
if (A> 64 && A< 78) return A+13
if (A> 77 && A< 91) return A-13
return A }

function Rot13(X) { var j, Y = ""
for (j=0 ; j < X.length ; j++)
Y += String.fromCharCode(R13(X.charCodeAt(j)))
return Y }
Another approach, for later browsers, could be to use

S1 = S0.replace(/[a-z]/gi, XXX)

where XXX is a function resembling R13.

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4 ©
<URL:http://www.jibbering.com/faq/>? JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
Jun 14 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: nib | last post by:
What kind of problems is visual basic best at solving?
11
by: Venkatarajan | last post by:
hai, At present I'm facing a strange problem. We are converting a project from VB to .NET One record contains Chr(0). Let the record be of length 1800. In the 50th byte of a record a chr(0) is...
2
by: crjunk | last post by:
I have the following code in my web page. Dim tmpReplace As String 'Giving tmpReplace the value from the textbox on the webform. tmpReplace = txtComments.Text.Trim 'Prevents report from...
3
by: John T. Howard | last post by:
I just found out how to access WMI to get system information from an example on the Web. Now I'm wondering what all I can get from WMI, do you know a good source for documentation? Thanks, ...
2
by: TPK | last post by:
I have an HTML document with Javascript where I have a portion of the page contents, a series of questions, being pulled from a XML file. When the page dynamically builds all the questions and...
3
by: ics3djc | last post by:
Hi. Is there a way to remove carriage returns and line feeds from a field in SQL. Here is what I have at the moment: CAST(m.Description AS VARCHAR(8000))AS "Product Description" (have had...
1
by: Vivienne | last post by:
Hi, I am using a c# library in my c++ project. so I have to convert a basic string to System::string to make use of a function that takes System::String as argument. I did it like this: ...
1
by: pravinnweb | last post by:
hi i want to learn javascript ..can anyone suggest any book or any site from which i can learn javascirp...with easy examples....except w3schools?...thanks in advance ....
4
by: robain | last post by:
I am looking for an isolated piece of code that uses XmlHttpRequest/JavaScript to download files from a (specified path on a) server to local machine. The browser on the local machine...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.