String2Hex
These functions only works for ASCII-7 non-control characters.
<lsl>
string c_chr=" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
// http://wiki.secondlife.com/wiki/Int2Hex
string int2hex(integer x){
string toret;
do{
toret=llGetSubString("0123456789ABCDEF",x&0x0000000F,x&0x0000000F)+toret;
}while (x=x>>4&0x0FFFFFFF);
return toret;
}
string str2hex(string str){ string ret=""; integer strlen=llStringLength(str); integer i=0; for(;i<strlen;++i){ ret+=int2hex(32+llSubStringIndex(c_chr,llGetSubString(str,i,i))); } return ret; }
string hex2str(string str){ string ret=""; integer strlen=llStringLength(str); integer i=0;integer index; for(;i<strlen;i+=2){ index=((integer)("0x"+llGetSubString(str,i,i+1)))-32; ret+=llGetSubString(c_chr,index,index); } return ret; }
default{ state_entry(){ llOwnerSay(str2hex("test ~")); llOwnerSay(hex2str("74657374207E")); } } </lsl>