|
harley Apprentice
Joined: 05 Apr 2008 Posts: 121
|
Posted: Fri Oct 29, 2010 12:02 pm
3.31// Script question |
I think i've answered this myself, but it doesnt seem to be the best way.. maybe it is.
I have a var QuestMob
The current value is "laying goose"
If I wanted to pick only the first word in the value, ie. laying is there a simple solution?
my idea was
Code: |
questmob = %replace(QuestMob, " ",|) |
would that work and be efficient?
I havent tried it as i'm at work currently. |
|
|
|
Rahab Wizard
Joined: 22 Mar 2007 Posts: 2320
|
Posted: Fri Oct 29, 2010 1:34 pm |
It does work. I have used similar replace functions to tokenize strings, letting me examine each word individually. Your statement would probably more like
Code: |
questmob = %replace(@QuestMob, " ","|") |
If you only want the first word, you could also do use something like %match(%trim(@questmob),"^(%w)",$firstword). |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Fri Oct 29, 2010 2:41 pm |
Using %match() in this case would be far less efficient than %replace() or %word() (%word() is designed to let you retrieve individual words by position, given some sort of delimiter).
|
|
_________________ EDIT: I didn't like my old signature |
|
|
|
|
|