|
Bloodsong Termagant
Manic Artist
Join date: 22 Jan 2007
Posts: 615
|
10-17-2008 07:41
heyas; so... string line = "\n\t blah blah" translates to 'blah blah' on a new line with a tab in front of it. great! now i put a buncha strings in notecards with \n and \t codes. and when i do string line = data.... it comes out as '\n\t blah blah' this is not fun. when i do string line = data; string realline = line. it doesnt get rid of the \n\t codes. apparently, i have to write a function to replace \n with... um... \n and \t with \t. recursively until they're all replaced. uh... okay, i admit, i'm stumped as to how to do that  any ideas? is there a utf code for newline and/or tab i can stick in and then use llescapeurl or unescapeurl or whichever it is?
_____________________
Why Johnny Can't Rotate: http://forums.secondlife.com/showthread.php?t=94705
|
|
Bloodsong Termagant
Manic Artist
Join date: 22 Jan 2007
Posts: 615
|
Fix
10-17-2008 07:59
heyas; for a while i thought i'd have to go through my notecards and use custom codes. but... i discovered it could find \\ (and/or \\n and \\t) in the notecard line data so.... this function fixes it.
//--FORMAT NTs------------------------------------------------------ string formatNT(string s) { string front; string back; while(llSubStringIndex(s, "\\n") != -1) { front = llGetSubString(s, 0, llSubStringIndex(s, "\\n")-1); back = "\n"+llGetSubString(s, llSubStringIndex(s, "\\n")+2, llStringLength(s)); s = front+back; } while(llSubStringIndex(s, "\\t") != -1) { front = llGetSubString(s, 0, llSubStringIndex(s, "\\t")-1); back = "\t"+llGetSubString(s, llSubStringIndex(s, "\\t")+2, llStringLength(s)); s = front+back; } return s; }
|
|
Pedro McMillan
SLOODLE Developer
Join date: 28 Jul 2007
Posts: 231
|
10-17-2008 08:22
This is often a source of frustration in other programming languages too. Basically, when you use "\n" or "\t" in a string in your script, it's not actually stored as "backslash n" or "backslash t"... the compiler converts it to the appropriate ASCII character for "newline" or "tab". In the same way, the compiler converts "\\" to just a single backslash character. Obviously text you read in from a notecard isn't compiled, so the characters never get converted.
|
|
Pale Spectre
Registered User
Join date: 2 Sep 2005
Posts: 586
|
10-17-2008 09:10
When I've read a string from a Notecard this works for me... string = llDumpList2String(llParseStringKeepNulls(string, ["\\n"], []), "\n"  ; string = llDumpList2String(llParseStringKeepNulls(string, ["\\t"], []), "\t"  ;
|
|
Strife Onizuka
Moonchild
Join date: 3 Mar 2004
Posts: 5,887
|
10-17-2008 18:02
Bloodsong, that bit of code is going to send you into a world of hurt when you try to use the "\\" escape code in a string like "\\new\\" Fortunately I wrote a function to deal with this problem some time ago... but it's too much work for me to get at it right now so I wrote a new one ^_^ you can find it here: http://wiki.secondlife.com/wiki/Combined_Library#Unescape
_____________________
Truth is a river that is always splitting up into arms that reunite. Islanded between the arms, the inhabitants argue for a lifetime as to which is the main river. - Cyril Connolly
Without the political will to find common ground, the continual friction of tactic and counter tactic, only creates suspicion and hatred and vengeance, and perpetuates the cycle of violence. - James Nachtwey
|