Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
alexcn
Newbie


Joined: 19 Jan 2002
Posts: 6

PostPosted: Sat Jan 19, 2002 3:56 pm   

a question in string operating
 
the question is as following, I could not find a good answer:
in a text file or a database, there are some lines of string, such as
abcde
bcdef
cdefg

then another string are given picked from it but with a random order, such as "cbdea", from this given string, how could I pick out the relative one(should be "abcde") from the text file or the database?

thanks in advance
Reply with quote
Troubadour
GURU


Joined: 14 Oct 2000
Posts: 556
Location: USA

PostPosted: Sun Jan 20, 2002 8:20 am   
 
The following script assumes that no letters repeat themselves.


#VAR randomstring %1 // or however you want to define it.
#VAR foundIt 0
#FILE 1 relatives.txt
#VAR record 0
#UNTIL @foundIt {
#ADD record 1
#VAR testword %read(1, @record)
#VAR goodLetterCnt 0
#LOOP %len(@randomstring) {
#IF %pos(%copy(@randomstring, %i, 1), @testword) {#ADD goodLetterCnt 1}
}
#IF (@goodLetterCnt = %len(@randomstring)) {#VAR foundit 1}
}
#SAY The relative of @randomstring is @testword~.
#CLOSE 1


Basically, it pulls a test word from the file, then checks to see if each letter of the random string is in the test word. If so, it reports, if not, it moves on to the next test word.

Troubadour
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
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

© 2009 Zugg Software. Hosted by Wolfpaw.net