String Handling

Function names shown in green are actually macros defined in userdefs.udf. See Macros.

NOTE: In the string handling functions below, indices are base 1; that is, the first character in a string is at position 1.

@asc[$s,@index]
ASCII value of a character in string $s. The @index is optional; if not specified then the first character of the string is assumed.

@len[$s]
Length of string $s

@cmp[$s1,$s2]
Compares strings; result is negative if $s1<$s2, positive if $s1>$s2, or 0 if $s1=$s2

@icmp[$s1,$s2]
Same as @cmp but case insensitive

@ncmp[$s1,$s2,@n]
Like @cmp, but only compares first @n characters

@nicmp[$s1,$s2,@n]
Like @icmp, but only compares first @n characters

@mat[$mask,$s]
Wildcard comparison (use ? and * as in filename comparison)

@par[$s,$delim]
Count of parsels (words) in $s, separated by delimiter $delim. (Use " " (space) for $delim in most cases.) Example: @par["this is a test"," "] returns 4, because there are 4 words in that string.

@par_[$s,$delim,$chleft,$chright]
Like @par except ignores delimiters between specified characters, as well as between quotes. The specfied character arguments are optional; if none given, then braces { } are assumed.

@chrcnt[$s,$ch]
Count of occurrances in $s of character $ch.

@ind[$lookfor,$lookin,$delim,@start]
Index of parsel in $lookin that matches $lookfor (case insensitive). Example: @ind["a","this is a test"," "] returns 3 because "a" is the 3rd word in that string. The optional @start argument specifies the parsel to begin searching at, if other than the beginning.

@wind[$mask,$lookfor,$delim,@start]
Same as @ind, except allows wildcards (* and ?).

@pos[$lookfor,$lookin,startat]
Position of $lookfor in $lookin. (First position is 1.) Example: @pos["this is a test","test"] returns 11 because "test" begins at the 11th position (character) in the string. As of version 6.6.7, you can also use the optional argument @startat, to specify where to start looking (useful for searching for multiple occurances of a string).

@ipos[$lookfor,$lookin,startat]
Case insensitive version of @pos

@posl[$lookfor,$lookin]
Position of last occurance

@iposl[$lookfor,$lookin]
Case insensitive version of @posl

$cat[$s1,$s2, ...]
Returns the concatenation of $s1,$s2 etc. For example: $cat["this ","is ","a ","test!"] returns "This is a test!"

$sub[$s,@start,@length]
Returns segment of $s beginning at position @start, @length characters long.
For example: $sub["This is a test",6,2] returns "is".

$str[@n]
Converts numerical value to string, e.g. numeral 12 to string "12".

$asc[@a]
Returns string containing character with ASCII value @a.

$seg[$s,@i1,@i2]
Segment of $s between positions @i1 and @i2, inclusive.

$left[$s,@length]
Leftmost @length characters of $s.

$right[$s,@length]
Rightmost @length characters of $s

$tail[$s,@start]
Segment of $s from position @start to the end of the string.

$par[$s,$d,@n]
Returns the @nth "parsel" (word) in $s, between delimiters $d. Ignores delimiters between quotes.
For example: $par["this is a test"," ",4] returns "test", the fourth word in that string.

$par_[$s,$d,@n,$chleft,$chright]
Like $par except ignores delimiters between specified characters, as well as between quotes. The specfied character arguments are optional; if none given, then braces { } are assumed.

$words_[$s,@n1,@n2,$delims]
A string consisting of words @n1 to @n2, inclusive, of the specified string $s.

$gets[$caption,$prompt,$default]
Prompts user to enter a string in a small pop-up window. Returns the $default if user clicks on Cancel.

$edit[$caption,$prompt,$default]
Prompts user to enter text in the large Edit Box window. Returns $default if user clicks on Cancel.

$file[$filename]
Returns the contents of a text file, up to max string length=1024 bytes. (You could use this with DO (like DO $file["MyMethod.txt"]) to execute small scripts stored in text files.)

$fmt[$format,<variable list>]
Returns a formatted text string, with values inserted. For example: $fmt["world name=%s, avatar=%s.",$atr[world_name],@atr[my_type]] returns something like "world name=aw, avatar=1." NOTE: Always use %s as the specifier in the $fmt function, whether the variable is a string or numeric. In similar functions in C and Delphi Pascal, you are able to use other specifiers like %d for decimal number, %f for floating point, etc., but in Magsbot you always use %s regardless of the variable type. (This is because, technically, MB variables are all "variant" type, which require the %s specifier.)

In Magsbot 2.0, escape sequences are not performed except in $es or $fmt.

$fmt_[$format,<variable list>]
Acts the same as $fmt, except does not perform escape sequence conversion. (New in Magsbot 2.0.)

$es[$s]
Performs escape sequence substitutions on string $s. New in Magsbot 2.0.

$replace[$s,$old,$new]
Replaces all occurances in $s of substring $old with substring $new and returns the result. Be careful that $new doesn't contain $old (for instance, $old="a", $new="another") or an infinite loop will result, requiring you to press F12 to break out of the function.

$lc[$s]
Returns $s converted to lowercase

$uc[$s]
Returns $s converted to uppercase

$trim[$s]
Returns $s with leading & trailing spaces trimmed off.

$triml[$s]
Returns $s with leading spaces trimmed off.

$trimr[$s]
Returns $s with trailing spaces trimmed off.

$quote[$s]
Returns $s with quotes added at the beginning and end, and converts single quotes to double quotes.

$unquote[$s]
Returns $s with quotes removed from the beginning and end, and converts double quotes to single quotes.

$getfname[$prompt,$default]
Display a File Open dialog and get a filename from the user.

Specific to Active Worlds

$chat
The incoming chat string.

$botname
The bot's name.

$words[@n1,@n2]
A string consisting of words @n1 to @n2, inclusive, of the incoming chat string.

@chattype[awchattype]
Returns a numerical value from the chat type constant. Example: @chattype[WHISPER].

$word[@n]
Returns word number @n of the incoming chat string.

@word[$s]
The word number of $s in the incoming chat string. For example, if the chat string is "Hello, how are you today?", then @word["how"] would return 2.

@words
Returns a count of the number of words in the incoming chat string.

@w[$text]
True if word $text is found in a chat string and @botcmd is true (1). (Also returns true if $text+"s" is found. Thus @w[test]would find either "test" or "tests".

@phr[$phrase]
True if phrase $phrase is found in a chat string and @botcmd is true (1).

@w1
Number of the first word in the chat string other than the bot's name; i.e., =1 if bot name isn't used, =2 if bot name is used.

$w1
The first word in the chat string other than the bot's name.

$w2
The second word in the chat string other than the bot's name.

$ww
Remainder of chat string after first word, not counting bot name e.g. if chat is "mags follow the big avatar" then $ww would be "the big avatar".



This function was REMOVED. You should use @ipos instead.
@str_in[$lookfor,$lookin,$delims]
Returns true if multi-word string $lookfor is found in multi-word string $lookin. (Note delims must logically be the same for both $lookin and $lookfor). The function compares $lookfor with each segment of $lookin of the same length as $lookfor. Note this searchs for only ONE lookfor, e.g. @str_in["good afternoon",$chat,$chatdelims]

Search for a word or phrase in a string, specified by a delimited group of words or phrases:

@iposw[$lookfor,$lookin,$lookfordelims,$lookindelims,@wildcard]
Search string for any one of a group of delimited words/phrases; returns true if any word/phrase in the group of words/phrases is found in the string. (Returns the index of the word/phrase within the $lookfor string.) The arguments are $lookfor = the specifier string (e.g. "apple|orange"), $lookin= the string to search in (e.g. $chat), $lookfordelims = e.g. "|", $lookin delims = e.g. $chatdelims.  The optional @wildcard argument, added in version 6.5.24, lets you use wildcard specifiers (like * and ?) in the lookfor items.

@word_in[$lookfor,$lookin,$delims]
Derived from @iposw, using the $chatdelims macro for the $lookindelims argument. For example, @word_in["apple|plum|kiwi fruit|orange",$chat,"|"] will return true if "apple", "plum", "kiwi fruit" or "orange" are in the chat string.

@instr[$lookfor]
Derived from @iposw, using $chat for the the $lookin argument and the $chatdelims macro for the $lookindelims argument and a pipe symbol ( | ) for $lookfordelims. For example, @instr["apple|plum|kiwi fruit|orange"] will return true if "apple", "plum", "kiwi fruit" or "orange" are in the chat string.

@wi[$lookfor]
The same as @instr. For backward compatibility.

@wi1[$s]
This is the same as @wi, except it only looks at the first word of $chat.

@ww[$s]
This is the same as @wi, but only returns true if the chat is directed at the bot.
 

Search for a word or phrase in a string, specified by a string list of words or phrases:

@wordinlist[$lookforlist,$lookin,$delims,@start]
Search a string for any one of a list of items: returns true if any item in the specified list, is found in the specified string (returns the index in list if found or 0 if not found). The arguments are $lookforlist = the list name, $lookin = the string to search in (e.g. $chat), $lookin delims = (e.g. $chatdelims). (The optional @start argument indicates the list item to begin searching at; @start was added in version 5.2 b8.)
Example: @wordinlist[mylistofwords,$chat,$chatdelims]

@wordin[$list,$s]
Derived from @wordinlist, using the  $chatdelims macro for the $delims argument.  NOTE: In the old version of this function, you needed to call RESETLIST before calling @wordin. This is no longer necessary.

@inlist[$list]
Derived from @wordinlist, using $chat for the $lookin argument and the $chatdelims macro for the $delims argument.  Example: @inlist[mylist] will return true if any of the words or phrases in list "mylist" are within the chat string.
 

$AWB[@NS,@WE,@Alt,@Yaw]
This macro takes a set of SDK-style coordinates and returns the equivalent AWB coordinates as a string. (For instance $AWB[21000,-775200,0,1800] returns "21N 775.2E 0a 180".

@SDKcoords[$AWBcoords,$WORLDvar,$NSvar,$WEvar,$ALTvar,$YAWvar]
This function is used to translate a string of AWB coordinates into SDK-type coordinates. The first argument is an input string, like  "AW 21N 775.2E 0a 180" (the world name is optional). The other five arguments are the names of the variables that the SDK coordinates will be stored in.  IMPORTANT NOTE! Remember that the final five arguments are NOT the variables themselves, but the NAMES of the variables. For example: @SDKcoords["AW 21N 775.2E 0a 180",N,Z,X,Y,F] would store the translated coordinates into local variables $N (the world name, or an empty string if the world name is omitted), @Z (the NS coordinate), @X (the WE coordinate), @Y (the altitude) ,@F (the yaw). You DO NOT put the "$" or "@" prefixes in from of the variable names specified as arguments to the function.  The function returns 1 (true) if successful, or 0 (false) if it fails.  No error is generated if the coordinates are incorrect, so be sure to check the value that the function returns to make sure the conversion occurred properly.

Back to Functions