Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 04-17-2008, 04:27 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
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.
Reply With Quote
  #2  
Old 04-17-2008, 06:58 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
PHP Code:
str.tokenize("\"test\""); 
__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #3  
Old 04-17-2008, 07:53 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
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.
Reply With Quote
  #4  
Old 04-17-2008, 08:44 PM
Tigairius Tigairius is offline
The Cat
Tigairius's Avatar
Join Date: Jan 2007
Location: Missouri, USA
Posts: 4,240
Tigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant futureTigairius has a brilliant future
Quote:
Originally Posted by Crow View Post
Did you read my post at all? o.O blah blah blah..
PHP Code:
temp.tokn newString.tokenize("\\");
for (
temp.itokn) {
  
ChatBar.text @= i;

__________________


“Shoot for the moon. Even if you miss, you'll land among the stars.”
Reply With Quote
  #5  
Old 04-17-2008, 10:09 PM
Crow Crow is offline
ǝɔɐɹq ʎןɹnɔ
Crow's Avatar
Join Date: Dec 2006
Location: Germany
Posts: 5,153
Crow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond reputeCrow has a reputation beyond repute
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.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 01:32 AM.


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