PDA

View Full Version : Keeping quotation marks when using tokenize()


Crow
04-17-2008, 04:27 PM
Let's say I got a string which includes quotation marks. They are killed when using tokenize() on that string, but I need to keep them. I figured out that when using escape() on the string before using tokenize() will most likely fix it, but theres one problem.
After modifying the string's single parts, I'm putting it together again and I'm then putting it in a TextEdit Control. Here comes the problem: the backslashes will remain.

Things like this:
"test"
Will then look like this:
\"test\"

So, how could I get rid of the backslashes after the string was put together again, or how do I use tokenize() on the string without getting rid of the quotation marks at all.

Tigairius
04-17-2008, 06:58 PM
str.tokenize("\"test\"");

Crow
04-17-2008, 07:53 PM
Did you read my post at all? o.O
I'm already doing this most likely, since string.escape() will put backslashes infront of several characters. But the backslashes will remain when then putting the string into a TextEdit Control.

Let's say the player says the following:
test1 "test2" test3, test4

temp.string = player.chat.escape().tokenize();

//stuff modifying the string

temp.newString = "";
for (temp.c: temp.string)
newString @= c @ " ";

ChatBar.text = newString;

Will result in this:
test1 \"test2\" test3, test4

And exactly this being put into the chatbar. Just an example, hope you get what I mean.

Tigairius
04-17-2008, 08:44 PM
Did you read my post at all? o.O blah blah blah..


temp.tokn = newString.tokenize("\\");
for (temp.i: tokn) {
ChatBar.text @= i;
}

Crow
04-17-2008, 10:09 PM
Thanks to Tig for some ingame help. Unfortunately we couldn't come up with an efficient way that works, but after he left, I still had an idea and turned it into something that seems to be pretty efficient. Not as much as other things, but it's still working and doesn't eat alot of CPU.
If anybody else is looking for a solution, I'm going to share this with you. It eliminates the backslashes that are created by escape(), and only those.

while (newChat.pos("\\\"") > -1 || newChat.pos("\\'") > -1 || newChat.pos("\\\\") > -1) { //"
if (newChat.pos("\\\"") > -1) //"
newChat = newChat.substring(0, newChat.pos("\\\"")) @ newChat.substring(newChat.pos("\\\"") + 1);
else if (newChat.pos("\\'") > -1)
newChat = newChat.substring(0, newChat.pos("\\'")) @ newChat.substring(newChat.pos("\\'") + 1);
else
newChat = newChat.substring(0, newChat.pos("\\\\")) @ newChat.substring(newChat.pos("\\\\") + 1);
}

There are some comments here and there with just a quotation mark. I added those to fix the syntax highlighting that has some problems with the escaped quotation mark.