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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Adrone
Newbie


Joined: 01 Dec 2011
Posts: 2

PostPosted: Sat Jul 14, 2012 11:29 pm   

searching a string list variable
 
I have a string list with character names that I am trying to search and display the results. Problem is that it will return the results of my search if the letters are anywhere in the name. I am trying to get it to display results only if the names start with the letters I enter. For example the alias is named search. I type search abc. I currently get results of abcd, , abce, nabc, jabc, etc. I would like it to return abcd, abce only. I've read and tried %left but I can't seem to get it to work right. any help would be appreciated. Below is what I am using.

$search = ""
#loop 1,%numitems(@charnames) {#IF %match(%item( @charnames, %{i}),%1) {#additem $search %item(@charnames, %{i})}}
say %replace( $search, "|", ", ").


Thanks

well, I figured it out, I added ^ in front of %1
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Sun Jul 15, 2012 1:15 am   
 
There are several ways of doing this. You could, for instance, change your match pattern so that it only matches at the beginning of the string. But probably the easiest is to use the %begins() function instead of %match().
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD 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