Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

Getting the ASCII value of a character

White Hyacinth
Registered User
Join date: 15 Nov 2006
Posts: 353
06-12-2007 16:14
In my script I need to find out the ASCII-value of a character. I have seen scripts where they define a string like " !"#$%...]~" and use getindex to find the value. That is an utterly ugly solution!
Isn't there a better way?
DoteDote Edison
Thinks Too Much
Join date: 6 Jun 2004
Posts: 790
06-12-2007 16:21
There's no LSL function to do it. So, you have to build the list in numerical order, and calculate based on the index of your character within that list.

Only other way I can think is to script a web applet and use your script to httprequest to your applet when a lookup is needed.
White Hyacinth
Registered User
Join date: 15 Nov 2006
Posts: 353
06-13-2007 02:42
From: DoteDote Edison
Only other way I can think is to script a web applet and use your script to httprequest to your applet when a lookup is needed.

Hehehe, cool! Thank you.
No, I don't think I will do that.
:)
I just can't stand it to know the right combination of bits is present in the computer and I still have to use tricks like this to get at them.
:(
On the bright side: If I would ever want to convert a character to its EBCDIC-code I would only have to put the search string in a different order.
:)
Newgate Ludd
Out of Chesse Error
Join date: 8 Apr 2005
Posts: 2,103
06-13-2007 10:21
Try this, only works for printabel ascii

CODE

string characters = " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~";


integer Asc(string str)
{
string s = llGetSubString(str,0,0)
integer index = llSubStringIndex(characters, s);
if(index >= 0) index += 32;

return index;
}

string Chr(integer val)
{
integer len = llStringLength(characters);
integer index = val - 32;
if( (index >= 0) && (index <= len )
{
return llGetSubString(characters,index,index);
}
else
return "";
}
_____________________
I'm back......