String functions

Jump to: navigation, search
See also: Message functions

These are various functions for manipulating and converting strings in HeroScript.



function tokenize(line as string, tokens references list of string)

This is a built-in function (accessible to both client and server) that breaks up the input string into pieces like command line parameters -- words or phrases. It separates tokens by looking for spaces. Phrases contained within double quotes (") or parentheses are treated as single tokens, even if they involve multiple words.

                                             // If the inputString is:
                                                          doGoodThing red "a phrase to use"
  tokens as list of string
  Tokenize(inputString, tokens)
                                             // will result in 3 strings in the token list:
                                             //        doGoodThing
                                             //        red
                                             //        a phrase to use
  println(tokens[1])                         //  This would print "doGoodThing"

Split a string into a list of strings

This built-in function populates a list of strings by copying elements from a single string that are designated by a separator character.

function SplitBy( source as string, separator as string, result as list of string)

It can be especially useful when dealing with Remote Call functions, which need to pass information back and forth between servers and the client. Since the functions can only pass strings, but sometimes it is necessary to pass non-string data. For example, a "Serialization" process can be used to combine several pieces of non-string data into a string, in order for it to be passed. Then the SplitBy function can ube used to split the data back up into its component parts. For more information, please see the Code Snippets page.

Integer to String

This is a built-in conversion function, which converts an integer i and returns a string value.

function itos( i as integer) as string
i_string = itos(i)

String to Integer

This is a built-in conversion function, which converts a string value to an integer i.

function stoi( s as string) as integer

Float to String

This is a built-in conversion function.

function ftos( f as float) as string
println("output = " + ftos(5))
   output = 5.0

String to Float

This is a built-in conversion function.

function stof(s as string) as float

Boolean to String

This is a built-in conversion function.

function btos(bVar as boolean) as string

Extract Substring

This external function extracts a substring from a larger string by specifying its location and length. The first character of the string is counted as "1".

function SubString( source as string, start as integer, length as integer) as string


sourceString = "Now is the time for all good gamers to roll the dice."
println( subString(sourceString, 12, 4))               // Would result in "time"

Find String

There are two built-in functions which will search through a string (the "haystack") looking for a specific substring (the "needle").

FindString starts at the beginning of the haystack string, and searches all the way through:

function FindString( haystack as string, needle as string) as integer

FindStringEX will start at a specific position (start) in the haystack, when it does its search. The first character of the string is position #1.

function FindStringEX( haystack as string, needle as string, start as integer) as integer

Convert a string to ALL UPPERCASE

function toUpper(stringVar as string) as string


  stringVar = toUpper(stringVar)

CONVERT A STRING TO all lowercase

function toLower(stringVar as string) as string.


  stringVar = toLower(stringVar)

Replace String

This built-in function will do a search and replace through a string. Every found instance is changed, so it is like a global search and replace. The search is case-sensitive.

ReplaceString(source as string, findString as string, replaceString as string) as string


  source = "go spot go"
  newString = replaceString(source, "go" , "stop")
  println(newString)                                      // Results in "stop spot stop"

Copy Text to Clipboard

Client Only:

function CopyTextToClipboard(text as String)

String Tokens

Inserting Return or Quote marks in a string

Two 'symbols' exist to allow you to insert a hard return or quote marks into a string.

$R inserts a return and $Q inserts quote (") marks

To insert a dollar sign use two $s. Example: $$


str as string = "This is line one.$RThis is $Qline$Q two."

would result in an output of:

This is line one.
This is "line" two.

See also

Personal tools