 |
ugcity Newbie
Joined: 24 Jul 2010 Posts: 2
|
Posted: Sat Jul 24, 2010 7:55 pm
Extracting substring base on index |
Hi everyone.
I am struggling on extracting substring base on index of string by zscript.
For example there is a string "Hello World", how can I extract the characters from position 3 to 8, that is "llo Wo" and put it in a variable?  |
|
|
 |
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Sun Jul 25, 2010 1:34 am |
In Visual Basic the equivalent would be the MID() function, but in CMud it's a combination of two functions out of a possible 4:
%right()
%left()
%rightback()
%leftback()
Each one takes two arguments, the first being the string to work on and the second being the character position to start. |
|
_________________ EDIT: I didn't like my old signature |
|
|
 |
ugcity Newbie
Joined: 24 Jul 2010 Posts: 2
|
Posted: Sun Jul 25, 2010 5:04 am |
I got it. Thanks a lot. 
|
|
|
 |
markb Beginner
Joined: 15 Jul 2010 Posts: 12
|
Posted: Wed Jul 28, 2010 4:39 pm |
Actually there is a cleaner version using one command %copy;
Syntax: %copy(string,start,len)
return a portion of string, starting at character position start (the first character is position 1), and returning len characters. If len is missing, then the rest of the characters in the string are returned. If start is less than zero, then the start position is relative to the end of the string instead of the beginning. |
|
|
 |
|
|