Enfusion Script API
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
string Interface Reference
Inheritance diagram for string:
[legend]

Public Member Functions

proto external int ToAscii (int index=0)
 Gets the ASCII code of a character in the string.
 
proto external float ToFloat (float default=0.0, int offset=0, out int parsed=-1)
 Parses a float from a string.
 
proto external int ToInt (int default=0, int offset=0, out int parsed=-1)
 Parses an integer from a string.
 
proto external vector ToVector ()
 Returns a vector from a string.
 
proto external string Substring (int start, int len)
 Substring of str from start position len number of characters.
 
proto external string Trim ()
 Returns trimmed string with removed leading and trailing whitespaces.
 
proto external int TrimInPlace ()
 Removes leading and trailing whitespaces in string.
 
proto external int Length ()
 Returns length of string.
 
proto external bool IsEmpty ()
 Determines if string is empty.
 
proto external int Hash ()
 Returns hash of string.
 
proto external int IndexOf (string sample)
 Finds 'sample' in 'str'.
 
proto external int LastIndexOf (string sample)
 Finds last 'sample' in 'str'.
 
proto external int IndexOfFrom (int start, string sample)
 Finds 'sample' in 'str' from 'start' position.
 
proto external bool Contains (string sample)
 Retunrs true if sample is substring of string.
 
proto external bool ContainsAt (string sample, int pos)
 Checks whether the string contains a given substring at a given position.
 
proto external bool StartsWith (string sample)
 Checks whether the string begins with a given substring.
 
proto external bool EndsWith (string sample)
 Retunrs true if string ends with sample, otherwise return false.
 
proto external int Compare (string sample, bool caseSensitive=true)
 Compares with sample and returns an integer less than, equal to, or greater than zero if string is less than, equal to, or greater than sample.
 
proto external int Replace (string sample, string replace)
 Replace all occurrances of 'sample' in 'str' by 'replace'.
 
proto external int ToLower ()
 Changes string to lowercase.
 
proto external int ToUpper ()
 Changes string to uppercase.
 
proto external void Split (string delimiter, notnull out array< string > outTokens, bool removeEmptyEntries)
 Splits string into array of strings separated by delimiter.
 
proto external string Get (int index)
 Gets n-th character from string.
 
proto external bool IsDigitAt (int index)
 Checks whether a character at a given position is a digit.
 
proto external bool IsSpaceAt (int index)
 Checks whether a character at a given position is a whitespace.
 
proto external TypeName ToType ()
 Returns internal type representation.
 

Static Public Member Functions

static proto string Format (string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL)
 Builds a string using given format and arguments.
 
static proto string ToString (void var, bool type=false, bool name=false, bool quotes=true)
 

Static Public Attributes

static const string Empty
 

Member Function Documentation

◆ Compare()

proto external int string.Compare ( string  sample,
bool  caseSensitive = true 
)

Compares with sample and returns an integer less than, equal to, or greater than zero if string is less than, equal to, or greater than sample.

Parameters
samplestring to campare with
Returns
bool less than, equal to, or greater than zero if string is less than, equal to, or greater than sample
string str = "Hello";
Print( str.Compare("Hello") );
Print( str.Compare("heLLo") );
Print( str.Compare("heLLo", false) );
>> 0
>> -1
>> 0
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
proto external int Compare(string sample, bool caseSensitive=true)
Compares with sample and returns an integer less than, equal to, or greater than zero if string is le...

◆ Contains()

proto external bool string.Contains ( string  sample)

Retunrs true if sample is substring of string.

Parameters
samplestring Finding string expression
Returns
bool true if sample is substring of string
string str = "Hello World";
Print( str.Contains("Hello") );
Print( str.Contains("Mexico") );
>> true
>> false
proto external bool Contains(string sample)
Retunrs true if sample is substring of string.

◆ ContainsAt()

proto external bool string.ContainsAt ( string  sample,
int  pos 
)

Checks whether the string contains a given substring at a given position.

Parameters
sampleThe substring to test
posPosition to test for the substring (index of the string's character)
Returns
true if the string contains the given sample at the given position, false otherwise.
"Hello World".ContainsAt("Hello", 0); // true (maybe use string.StartsWith() instead?)
"Hello World".ContainsAt("World", 6); // true
"Hello World".ContainsAt("Hello", 6); // false

◆ EndsWith()

proto external bool string.EndsWith ( string  sample)

Retunrs true if string ends with sample, otherwise return false.

Parameters
samplestring Finding string expression
Returns
bool true if string ends with sample
string str = "Hello World";
Print( str.StartsWith("Hello") );
Print( str.StartsWith("World") );
>> false
>> true
proto external bool StartsWith(string sample)
Checks whether the string begins with a given substring.

◆ Format()

static proto string string.Format ( string  fmt,
void  param1 = NULL,
void  param2 = NULL,
void  param3 = NULL,
void  param4 = NULL,
void  param5 = NULL,
void  param6 = NULL,
void  param7 = NULL,
void  param8 = NULL,
void  param9 = NULL 
)
static

Builds a string using given format and arguments.

(Maximum output string size is limited to 8191 characters)

Parameters
fmtFormatting string - any string with special tokens %1 .. %9.
param1Replaces the "%1" token in the formatting string in the result
param2Replaces the "%2" token
Returns
The resulting string, i.e. the formatting string with all the %1 ... %9 replaced.
int a = 5;
float b = 5.99;
string c = "beta";
string test = string.Format("Ahoj %1 = %3 , %2", a, b, c);
Print(test);
>> 'Ahoj 5 = 'beta' , 5.99'

◆ Get()

proto external string string.Get ( int  index)

Gets n-th character from string.

Parameters
indexcharacter index
Returns
string character on index-th position in string
string str = "Hello World";
Print( str[4] ); // Print( str.Get(4) );
>> 'o'

◆ Hash()

proto external int string.Hash ( )

Returns hash of string.

Returns
int - Hash of string
string str = "Hello World";
int hash = str.Hash();
Print(hash);
proto external int Hash()
Returns hash of string.

◆ IndexOf()

proto external int string.IndexOf ( string  sample)

Finds 'sample' in 'str'.

Returns -1 when not found

Parameters
samplestring Finding string
Returns
int - Returns position where sample starts, or -1 when sample not found
string str = "Hello World";
Print( str.IndexOf( "H" ) );
Print( str.IndexOf( "W" ) );
Print( str.IndexOf( "Q" ) );
>> 0
>> 6
>> -1
proto external int IndexOf(string sample)
Finds 'sample' in 'str'.

◆ IndexOfFrom()

proto external int string.IndexOfFrom ( int  start,
string  sample 
)

Finds 'sample' in 'str' from 'start' position.

Returns -1 when not found

Parameters
startint Start from position
samplestring Finding string expression
Returns
int - Length of string s
string str = "Hello World";
Print( str.IndexOfFrom( 3, "H" ) );
Print( str.IndexOfFrom( 3, "W" ) );
Print( str.IndexOfFrom( 3, "Q" ) );
>> -1
>> 6
>> -1
proto external int IndexOfFrom(int start, string sample)
Finds 'sample' in 'str' from 'start' position.

◆ IsDigitAt()

proto external bool string.IsDigitAt ( int  index)

Checks whether a character at a given position is a digit.

Parameters
indexposition of the character in the string
Returns
true iff the character at the position is from the "0" .. "9" range

◆ IsEmpty()

proto external bool string.IsEmpty ( )

Determines if string is empty.

Returns
True if empty, False otherwise.

◆ IsSpaceAt()

proto external bool string.IsSpaceAt ( int  index)

Checks whether a character at a given position is a whitespace.

A whitespace may be e.g. Space (0x20 " "), Tab (0x09 "\t"), New Line (0x09 "\r", 0x0a "\n") etc.

Parameters
indexposition of the character in the string
Returns
true iff the character at the position is a whitespace

◆ LastIndexOf()

proto external int string.LastIndexOf ( string  sample)

Finds last 'sample' in 'str'.

Returns -1 when not found

Parameters
samplestring Finding string
Returns
int - Returns position where sample starts, or -1 when sample not found
string str = "Hello World";
Print( str.IndexOf( "l" ) );
>> 9

◆ Length()

proto external int string.Length ( )

Returns length of string.

Returns
int - Length of string
string str = "Hello World";
int i = str.Length();
Print(i);
>> i = 11
proto external int Length()
Returns length of string.

◆ Replace()

proto external int string.Replace ( string  sample,
string  replace 
)

Replace all occurrances of 'sample' in 'str' by 'replace'.

Parameters
samplestring to search in str
replacestring which replace sample in str
Returns
int - number of occurrances of 'sample' in 'str'
string test = "If the length of the C string in source is less than num, only the content up to the terminating null-character is copied.";
Print(test);
int count = test.Replace("the", "*");
Print(count);
Print(test);
>> string test = 'If the length of the C string in source is less than num, only the content up to the terminating null-character is copied.';
>> int count = 4
>> string test = 'If * length of * C string in source is less than num, only * content up to * terminating null-character is copied.'
proto external int Replace(string sample, string replace)
Replace all occurrances of 'sample' in 'str' by 'replace'.

◆ Split()

proto external void string.Split ( string  delimiter,
notnull out array< string outTokens,
bool  removeEmptyEntries 
)

Splits string into array of strings separated by delimiter.

Parameters
delimiterStrings separator
[out]outTokensArray with strings
removeEmptyEntriesIf true removes empty strings from outTokens array
array<string> strs = {};
string line = "The;quick;brown;fox;jumps;over;the;;dog;";
line.Split(";", strs, true);
for ( int i = 0; i < strs.Count(); i++ )
{
Print(strs.Get(i));
}
>> 'The'
>> 'quick'
>> 'brown'
>> 'fox'
>> 'jumps'
>> 'over'
>> 'the'
>> 'dog'
Definition: Types.c:150
proto native int Count()
O(1) complexity.
proto T Get(int n)
proto external void Split(string delimiter, notnull out array< string > outTokens, bool removeEmptyEntries)
Splits string into array of strings separated by delimiter.

◆ StartsWith()

proto external bool string.StartsWith ( string  sample)

Checks whether the string begins with a given substring.

Parameters
sampleThe substring to test
Returns
true if the string starts with the given sample, false otherwise.
"Hello World".StartsWith("Hello"); // true
"Hello World".StartsWith("World"); // false

◆ Substring()

proto external string string.Substring ( int  start,
int  len 
)

Substring of str from start position len number of characters.

(Maximum output string size is limited to 8191 characters)

Parameters
startPosition in str
lenCount of characters
Returns
string - Substring of str
string str = "Hello World";
string strSub = str.Substring(2, 5);
Print(strSub);
>> strSub = llo W
proto external string Substring(int start, int len)
Substring of str from start position len number of characters.

◆ ToAscii()

proto external int string.ToAscii ( int  index = 0)

Gets the ASCII code of a character in the string.

Parameters
indexIndex of the character, 0 by default.

◆ ToFloat()

proto external float string.ToFloat ( float  default = 0.0,
int  offset = 0,
out int  parsed = -1 
)

Parses a float from a string.

Any whitespaces at the beginning in front of a number in the string will be skipped.

Parameters
defaultWill be returned when the parsing fails (e.g. there's no number to parse)
offsetNumber of characters in the string to skip
parsedOut param - number of characters read
Returns
The parsed float (the default if the parsing failed).
"42.7".ToFloat() // returns 42.7
" 42abc".ToFloat() // returns 42.0
"abc42.7".ToFloat() // returns 42.7
"abc42.7".ToFloat(default: 17.6) // returns 17.6
"abc42.7".ToFloat(offset: 3) // returns 42.7
"42.7".ToFloat(parsed: len) // returns 42.7, len = 4
" 42.7".ToFloat(parsed: len) // returns 42.7, len = 5
"0".ToFloat(parsed: len) // returns 0.0, len = 1
"abc".ToFloat(parsed: len) // returns 0.0, len = 0
" ".ToFloat(default: 17.6, parsed: len) // returns 17.6, len = 0
"abc 42.7 abc".ToFloat(offset: 3, parsed: len) // returns 42.7, len = 5

◆ ToInt()

proto external int string.ToInt ( int  default = 0,
int  offset = 0,
out int  parsed = -1 
)

Parses an integer from a string.

Any whitespaces at the beginning in front of a number in the string will be skipped.

Parameters
defaultWill be returned when the parsing fails (e.g. there's no number to parse)
offsetNumber of characters in the string to skip
parsedOut param - number of characters read
Returns
The parsed integer (the default if the parsing failed).
"42".ToInt() // returns 42
" 42abc".ToInt() // returns 42
"abc42".ToInt() // returns 0
"abc42".ToInt(default: 17) // returns 17
"abc42".ToInt(offset: 3) // returns 42
"42".ToInt(parsed: len) // returns 42, len = 2
" 42".ToInt(parsed: len) // returns 42, len = 3
" 42.7".ToInt(parsed: len) // returns 42, len = 3
"0".ToInt(parsed: len) // returns 0, len = 1
"abc".ToInt(parsed: len) // returns 0, len = 0
" ".ToInt(default: 17, parsed: len) // returns 17, len = 0
"abc 42 abc".ToInt(offset: 3, parsed: len) // returns 42, len = 3

◆ ToLower()

proto external int string.ToLower ( )

Changes string to lowercase.

Returns length. Works with just ASCII characters

Returns
int - Length of changed string
string str = "Hello World";
int i = str.ToLower();
Print(str);
Print(i);
>> str = hello world
>> i = 11
proto external int ToLower()
Changes string to lowercase.

◆ ToString()

static proto string string.ToString ( void  var,
bool  type = false,
bool  name = false,
bool  quotes = true 
)
static

◆ ToType()

proto external TypeName string.ToType ( )

Returns internal type representation.

Can be used in runtime, or cached in variables and used for faster inheritance checking

Returns
typename Type of class
???

◆ ToUpper()

proto external int string.ToUpper ( )

Changes string to uppercase.

Returns length. Works with just ASCII characters

Returns
int - Length of changed string
string str = "Hello World";
int i = str.ToUpper();
Print(str);
Print(i);
>> str = HELLO WORLD
>> i = 11
@ WORLD
Tracing against terrain.
proto external int ToUpper()
Changes string to uppercase.

◆ ToVector()

proto external vector string.ToVector ( )

Returns a vector from a string.

Returns
vector Converted s as vector
string str = "1 0 1";
vector v = str.ToVector();
Print(v);
>> v = <1,0,1>
proto external vector ToVector()
Returns a vector from a string.
Definition: vector.c:13

◆ Trim()

proto external string string.Trim ( )

Returns trimmed string with removed leading and trailing whitespaces.

(Maximum output string size is limited to 8191 characters)

Returns
string - Trimmed string
string str = " Hello World "
Print( str );
Print( str.Trim() );
>> ' Hello World '
>> 'Hello World'
proto external string Trim()
Returns trimmed string with removed leading and trailing whitespaces.

◆ TrimInPlace()

proto external int string.TrimInPlace ( )

Removes leading and trailing whitespaces in string.

Returns length

Returns
int - Count of chars
string str = " Hello World ";
int i = str.TrimInPlace();
Print(str);
Print(i);
>> str = 'Hello World'
>> i = 11
proto external int TrimInPlace()
Removes leading and trailing whitespaces in string.

Member Data Documentation

◆ Empty

const string string.Empty
static

The documentation for this interface was generated from the following file: