Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Keeping quotation marks when using tokenize() (https://forums.graalonline.com/forums/showthread.php?t=79443)

Crow 04-17-2008 04:27 PM

Keeping quotation marks when using tokenize()
 
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

PHP Code:

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

PHP Code:

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

//stuff modifying the string

temp.newString "";
for (
temp.ctemp.string)
  
newString @= " ";

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

Quote:

Originally Posted by Crow (Post 1386399)
Did you read my post at all? o.O blah blah blah..

PHP Code:

temp.tokn newString.tokenize("\\");
for (
temp.itokn) {
  
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.

PHP Code:

while (newChat.pos("\\\"") > -|| newChat.pos("\\'") > -|| newChat.pos("\\\\") > -1) { //"
  
if (newChat.pos("\\\"") > -1//"
    
newChat newChat.substring(0newChat.pos("\\\"")) @ newChat.substring(newChat.pos("\\\"") + 1);
  else if (
newChat.pos("\\'") > -1)
    
newChat newChat.substring(0newChat.pos("\\'")) @ newChat.substring(newChat.pos("\\'") + 1);
  else
    
newChat newChat.substring(0newChat.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.


All times are GMT +2. The time now is 11:16 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.