|
Caesar Hawks
Registered User
Join date: 21 Jun 2007
Posts: 6
|
07-08-2007 12:05
Hi all, In my script I have to parse strings extracting the letters that compose them. When I try to recognize the substrings "è", "é", "à", "ì" and "ù" in my code, by using: ... if (letter=="é"  ... I get some compilation errors... how can i encode these characters in order to represent them? thank you! Caesar
|
|
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
|
07-08-2007 12:17
You have to encode them in UTF-8 and convert using llUnescapeURL. See the following thread for details:
forums.secondlife.com/showthread.php?p=1500162
You could either declare a separate global string for each character you want to test for, and convert them once at startup in default state_entry (which eats up memory), or use llUnescapeURL on the UTF-8 representation for each comparison (which would run somewhat more slowly). It depends on which is more important to you.
|
|
Boss Spectre
Registered User
Join date: 5 Sep 2005
Posts: 229
|
07-08-2007 14:10
Here's an example using global strings to store the characters: string e_grave; string e_acute; string a_grave; string i_grave; string u_grave;
default { state_entry() { e_grave = llUnescapeURL("%C3%A8"); e_acute = llUnescapeURL("%C3%A9"); a_grave = llUnescapeURL("%C3%A0"); i_grave = llUnescapeURL("%C3%AC"); u_grave = llUnescapeURL("%C3%B9"); llListen(0, "", llGetOwner(), ""); }
listen(integer channel, string name, key id, string message) { string letter = ""; integer len = llStringLength(message); integer i = 0; while (i < len) { letter = llGetSubString(message, i, i); if (letter == e_grave) llOwnerSay(e_grave + " found in string"); if (letter == e_acute) llOwnerSay(e_acute + " found in string"); if (letter == a_grave) llOwnerSay(a_grave + " found in string"); if (letter == i_grave) llOwnerSay(i_grave + " found in string"); if (letter == u_grave) llOwnerSay(u_grave + " found in string"); ++i; } } }
Run this, speak a sentence in chat, and it will confirm that it finds those characters. The other way would look something like this: ... if ( letter == llUnescapeURL("%C3%A8"  ) // check for è ... These characters seem to be ok in comments, just not in constant strings.
|
|
Deanna Trollop
BZ Enterprises
Join date: 30 Jan 2006
Posts: 671
|
07-08-2007 15:24
From: Boss Spectre These characters seem to be ok in comments, just not in constant strings. Of course, comments aren't compiled.  But yeah, that's pretty much exactly the script I was describing... I was just too lazy to type one out. 
|