TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

extraction of string

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help
View previous topic :: View next topic  
Author Message
dawang10



Joined: 14 Feb 2015
Posts: 66

PostPosted: Sat Feb 14, 2015 5:12 pm    Post subject: extraction of string Reply with quote

The question is a bit like this one

http://tintin.sourceforge.net/board/viewtopic.php?t=1999&highlight=substring

How can I get the number of pieces divided by | from string?
#var aa {dd;gg;a;b;c;d;e;|d;e;s;a;q;d;|ed;sd;u;d;enter;|out;out;out;hi}

here is 4

The position of | is not fixed.

then pick up one of pieces I want, such as the second one {d;e;s;a;q;d;} and define this as a new one.

ps, | can be replaced by other symbol.
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 346

PostPosted: Sat Feb 14, 2015 7:13 pm    Post subject: Reply with quote

You can play with #replace

Code:

#replace aa {;} {-}
#replace aa {|} {;}

#VARIABLE {aa}={dd-gg-a-b-c-d-e-;d-e-s-a-q-d-;ed-sd-u-d-enter-;out-out-out-hi}


now we can use all the #list methods

Code:

#list {newlist} create {$aa}

#VARIABLE {newlist}={{1}{dd-gg-a-b-c-d-e-}{2}{d-e-s-a-q-d-}{3}{ed-sd-u-d-enter-}{4}{out-out-out-hi}}

#list newlist size counter
#echo $counter
4

#echo $newlist[2]
d-e-s-a-q-d-


last thing to do is to restore the original separators

Code:

#replace {newlist[2]} {-} {;}

#echo $newlist[2]
d;e;s;a;q;d;
Back to top
View user's profile Send private message
dawang10



Joined: 14 Feb 2015
Posts: 66

PostPosted: Sun Feb 15, 2015 6:40 am    Post subject: Reply with quote

Thank you.

But what if the variables contain space

for example

#VARIABLE aa {dd;gg;give xxx to xxxx;b;c;d;e;|d;e;s;knock door ;q;d;|ed;sd;u;d;enter;|out;out;out;hi}

Can I define aa like this;

#var {aa} {{1} {dd;gg;give-xxx-to-xxxx;b;c;d;e} {2} {d;e;s;knock-door;q;d} {3} {ed;sd;u;d;enter} {4} {out;out;out;hi}}
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 346

PostPosted: Sun Feb 15, 2015 10:26 am    Post subject: Reply with quote

#list uses ";" as a separator when it create the array... spaces are not an issue while creating it

if for some reason you don't want to have spaces in the string you can replace them too, just choose wisely what substitutions you want to use for them.

In the example I used "-" because in my MUD it is not used for commands, but if that character can be already there, then you should use another one that you are sure it will not be present.

EDIT: just to be sure, you don't have to do this
Code:

#VARIABLE {newlist}={{1}{dd-gg-a-b-c-d-e-}{2}{d-e-s-a-q-d-}{3}{ed-sd-u-d-enter-}{4}{out-out-out-hi}}


it was just to show the result of #list create
Back to top
View user's profile Send private message
dawang10



Joined: 14 Feb 2015
Posts: 66

PostPosted: Sun Feb 15, 2015 12:07 pm    Post subject: Reply with quote

O, I see.

Many thanks
Back to top
View user's profile Send private message
PowerGod



Joined: 04 Aug 2014
Posts: 346

PostPosted: Sun Feb 15, 2015 1:57 pm    Post subject: Reply with quote

Wink
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Script Help All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group