Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

non-ASCII char recognition

Status
Not open for further replies.

mpalmer12345

Programmer
Feb 16, 2004
59
US
I'm trying to use extended chars in an array of strings, and Javascript is not recognizing the non-ASCII chars. I know there must be a way to fix this, but I can't find the info listed anyplace.

Here's a sample, containing 2 array elements between quotes. I would prefer to leave the elements in this form and not convert them to #s etc. I am looking for a solution like in Perl where one can use the \ in front of extended chars to single them out.

var bintexx = new Array (" ÔÉL? .", " ?p !UN");
 

Does your document have a content type specified? If not, try adding one to the HEAD section... Maybe something like:

Code:
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />

Not sure if this will make a big difference or not, but I know it makes a difference for characters such as £, etc.

I don't know if JavaScript fully supports double-byte unicode characters or not without using the &#xxxx; syntax or not, but try the code above and have a look anyway!

Hope this helps,
Dan

 
No, didn't work. It's like the array with extended chars isn't even recognized as a valid array. The program works with normal chars in the array, and fails when I add extended chars.
 

I tried a few tests, saving Javascript files as both UTF-8 and Unicode (using Notepad)and IE 6, NN 7, Opera 7, and Mozilla 1.5 work perfectly (even without the charset definition in the head)...

So if you can get the characters into your source file, then things should work OK:

Code:
<html>
<head>
<script type="text/javascript">
<!--
	var wibble = new Array('ŒRRR');
	alert('Array details\n\nLength: ' + wibble.length + '\nElement 0:' + wibble[0]);
//-->
</script>
</head>
<body></body>
</html>

The 4 characters in my array are all outside the "normal" character set.

Having said all of that, I'm not sure if you should do this for cross-platform purposes without testing it first ;o)

Hope this helps,
Dan
 

OK - so only one of the four characters posted as extended. The whole string was:

OE (Latin Capital Ligature Oe): U+0152
R (Latin Capital R with Acute): U+0154
R (Latin Capital R with Cedilla): U+0156
R (Latin Capital R with Caron): U+0158

I used Character Map and the Arial font to create the characters, and Notepad to save the file.

Dan
 
Okay, I found the problem, It's the old single vs double quotes for the strings.

Instead of

var bintexx = new Array (" ÔÉL? .", " ?p !UN");

I should have used

var bintexx = new Array (' ÔÉL? .', "'?p !UN');

like you did in your example, Dan.

Thanks!
 

Wow - I'm surprised that made a difference... Must be one of those things ;o)

I always try and use single quotes to delimit strings in Javascript if I can... Just a habit I've always been into, I guess.

Dan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top