Skip to content
Reference > Classes

String

Definition

String var = .... ;

Extends

Extended By

None

Description

A sequence of characters

Method Summary

Owner Name Return Type Description
String constructor(s) Object Initialize a string object
String after(toFind, origIfNotFound) String Get the portion of a string after the first occurence of a delimiter. If the delimiter is not found, then return either the original string or null depending on origIfNotFound param. Same as AmiScript strAfter().
String afterLast(toFind, origIfNotFound) String Get the portion of a string after the last occurence of a delimiter. If the delimiter is not found, then return either the original string or null depending on origIfNotFound param. Same as AmiScript strAfterLast().
String before(toFind, origIfNotFound) String Get the portion of a string before the first occurence of a delimiter. If the delimiter is not found, then return either the original string or null depending on origIfNotFound param. Same as AmiScript strBefore().
String beforeLast(toFind, origIfNotFound) String Get the portion of a string before the last occurrence of a delimiter. If the delimiter is not found, then return either the original string or null depending on origIfNotFound param.
String charAt(index) Character Returns the character at the specified index. Equivalent to the AmiScript method strChartAt().
String chars() List Returns a list whose length is the length of this string and whose contents are initialized to contain the character sequence represented by this string.
String cut(delim, fieldList) String Splits string using the supplied delimiter based on the supplied field positions. The string returned is the resulting strings or characters at the field positions joined by the delimiter. Same as AmiScript method strCut().
String decodeToByte() Byte Decodes a string into a byte. Must be a number without any suffix.
String decodeToLong() Long Decodes a string into a long. Must be a number without any suffix.
String decodeToShort() Short Decodes a string into a short. Must be a number without any suffix.
String endsWith(suffix, ignore_case) Boolean Returns "true" if this string ends with the specified suffix, "false" otherwise. Same as AmiScript method strEndsWith().
Object getClassName() String Returns the string name of this object's class type.
String indexOf(to_find) Integer Returns the index within this string of the first occurrence of the specified string, returns -1 if no such occurrence is found. Same as AmiScript method strIndexOf() with one argument.
String indexOf(to_find, start_index) Integer Returns the index within this string of the first occurrence of the specified string, starting from a specific index, returns -1 if no such occurrence is found. Same as AmiScript method strIndexOf() with two arguments.
String is() Boolean Returns "true" if the string contains characters other than whitespace characters, such as tabs, newlines, and spaces; returns "false" otherwise. Same as strIs(). Opposite of isnt().
String isEmpty() Boolean Returns "true" if, and only if, length() is 0 (i.e, an empty string).
String isnt() Boolean Returns "true" if the string contains only the following whitespace characters: tabs, newlines, and spaces; return "false" otherwise. Same as strIsnt(). Opposite of is().
String lastIndexOf(to_find) Integer Returns the index within this string of the last occurrence of the specified string, returns -1 if not found. This method is case sensitive, to ignore case use the other lastIndexOf() method and set the ignore case flag. Also equivalent to AmiScript method strLastIndexOf().
String lastIndexOf(to_find, last, ignore_case) Integer Returns the index within this string of the last occurrence of the specified string by searching from the specified index backwards. Returns -1 if not found. Same as AmiScript method strLastIndexOf(), with a suppliable ignore case flag.
String length() Integer Returns the length of this string. Same as AmiScript method strLen().
String replaceAll(to_replace, replacement) String Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence. Same as AmiScript method strReplace().
String splice(start, charsToReplace, replacement) String Replaces a base string's subsequence of chars with a replacement string. If start or charsToReplace extend beyond string limits, they will be set to string limits. Same as strSplice().
String split(delimiter) List Returns a list of strings, split by the given delimiter.
String splitLines() List Splits lines and returns a list of lines separated by line feed and line return chars.
String startsWith(s, ignore_case) Boolean Tests if this string starts with the specified prefix. Same as AmiScript strStartsWith().
String startsWith(s, start, ignore_case) Boolean Tests if this string starts with the specified prefix, starting from the given index.
String strip(prefix, suffix) String Same as AmiScript method strStrip(). Returns the substring of supplied text with the prefix and suffix removed. If the string doesn't start with the specified prefix, then the prefix is ignored. If the string doesn't end with suffix, then the suffix is ignored.
String substring(begin) String Returns a string that is a substring of this string, starting from the specified index to the end of the string.
String substring(begin, end) String Returns a string that is a substring of this string, start and end at specific index. Same as AmiScript strSubstring().
Object toJson() String Returns a string of a json representation of this object.
String toLower() String Converts all of the characters in this String to lower case using the rules of the default locale. Same as AmiScript strLower().
String toUpper() String Converts all of the characters in this String to upper case using the rules of the default locale. Same as AmiScript strUpper().
String trim() String Returns a string whose value is this string, with any leading and trailing whitespace removed. Same as strTrim().

Method Definitions


constructor(s)

String string = new String(String s)

Description

Initialize a string object

Parameter Definition

Name Type Description
s String  a String

Example 1

1
2
3
String s = "3forge";

// s = 3forge

after(toFind,origIfNotFound)

String String::after(String toFind, Boolean origIfNotFound)

Description

Get the portion of a string after the first occurence of a delimiter. If the delimiter is not found, then return either the original string or null depending on origIfNotFound param. Same as AmiScript strAfter().

Parameter Definition

Name Type Description
toFind String  The substring to find
origIfNotFound Boolean  If the toFind parameter doesn't exist in the text, then return text if true or null if false.

Example 1

1
2
3
4
5
6
String s = "3forge:company";
s.after(":company",true);
s.after("3forge",true);

// s.after(":company",true) = 
// s.after("3forge",true) = :company

afterLast(toFind,origIfNotFound)

String String::afterLast(String toFind, Boolean origIfNotFound)

Description

Get the portion of a string after the last occurence of a delimiter. If the delimiter is not found, then return either the original string or null depending on origIfNotFound param. Same as AmiScript strAfterLast().

Parameter Definition

Name Type Description
toFind String  The substring to find
origIfNotFound Boolean  If the toFind parameter doesn't exist in the text, then return text if true or null if false.

Example 1

1
2
3
4
5
6
String s = "3forge:company";
s.afterLast(":company",true);
s.afterLast("3forge",true);

// s.afterLast(":company",true) = 
// s.afterLast("3forge",true) = :company

before(toFind,origIfNotFound)

String String::before(String toFind, Boolean origIfNotFound)

Description

Get the portion of a string before the first occurence of a delimiter. If the delimiter is not found, then return either the original string or null depending on origIfNotFound param. Same as AmiScript strBefore().

Parameter Definition

Name Type Description
toFind String  The substring to delimit after
origIfNotFound Boolean  If the toFind parameter doesn't exist in the text, then return text if true or null if false.

Example 1

1
2
3
4
5
6
String s = "3forge:company";
s.before(":company",true);
s.before("3forge",true);

// s.before(":company",true) = 3forge
// s.before("3forge",true) = 

beforeLast(toFind,origIfNotFound)

String String::beforeLast(String toFind, Boolean origIfNotFound)

Description

Get the portion of a string before the last occurrence of a delimiter. If the delimiter is not found, then return either the original string or null depending on origIfNotFound param.

Parameter Definition

Name Type Description
toFind String  The substring to delimit before
origIfNotFound Boolean  If the toFind parameter doesn't exist in the supplied string, then return the full string if true or null if false.

Example 1

1
2
3
4
5
6
String s = "3forge:company";
s.beforeLast(":company",true);
s.beforeLast("3forge",true);

// s.beforeLast(":company",true) = 3forge
// s.beforeLast("3forge",true) = 

charAt(index)

Character String::charAt(Integer index)

Description

Returns the character at the specified index. Equivalent to the AmiScript method strChartAt().

Parameter Definition

Name Type Description
index Integer  Location of the character

Example 1

1
2
3
4
String s = "3forge";
s.charAt(0);

// s.charAt(0) = 3

chars()

List String::chars()

Description

Returns a list whose length is the length of this string and whose contents are initialized to contain the character sequence represented by this string.

Example 1

1
2
3
4
String s = "3forge";
s.chars();

// s.chars() = [3, f, o, r, g, e]

cut(delim,fieldList)

String String::cut(String delim, String fieldList)

Description

Splits string using the supplied delimiter based on the supplied field positions. The string returned is the resulting strings or characters at the field positions joined by the delimiter. Same as AmiScript method strCut().

Parameter Definition

Name Type Description
delim String  delimiter, literal not a pattern.
fieldList String  fields to return within a range n-m. Use n,m... for individual fields, or -n for number of fields up to and including that index, or n- for fields including and after that index.

Example 1

1
2
3
4
5
6
7
8
String s = "3,f,o,r,g,e";
s.cut(",","1-5");
s.cut(",", "1-");
s.cut(",", "-3");

// s.cut(",", "1-5") = f,o,r,g,e
// s.cut(",", "1-") = f,o,r,g,e
// s.cut(",", "-3") = 3,f,o,r

decodeToByte()

Byte String::decodeToByte()

Description

Decodes a string into a byte. Must be a number without any suffix.

Example 1

1
2
3
4
String s = "10";
Object b = s.decodeToByte();

// b.getClassName() = Byte

decodeToLong()

Long String::decodeToLong()

Description

Decodes a string into a long. Must be a number without any suffix.

Example 1

1
2
3
4
String s = "10";
Object l = s.decodeToLong();

// l.getClassName() = Long

decodeToShort()

Short String::decodeToShort()

Description

Decodes a string into a short. Must be a number without any suffix.

Example 1

1
2
3
4
String s = "10";
Object sh = s.decodeToShort();

// sh.getClassName() = Short

endsWith(suffix,ignore_case)

Boolean String::endsWith(String suffix, Boolean ignore_case)

Description

Returns "true" if this string ends with the specified suffix, "false" otherwise. Same as AmiScript method strEndsWith().

Parameter Definition

Name Type Description
suffix String  string to test
ignore_case Boolean  to ignore case set to "true", "false" otherwise.

Example 1

1
2
3
4
5
6
String s = "3forge";
s.endsWith("forge",true);
s.endsWith("hello",true);

// s.endsWith("forge",true) = true
// s.endsWith("hello",true) = false

getClassName()

String Object::getClassName()

Description

Returns the string name of this object's class type.

Example 16

1
2
3
4
String s = "3forge";
s.getClassName();

// s.getClassName() = String

indexOf(to_find)

Integer String::indexOf(String to_find)

Description

Returns the index within this string of the first occurrence of the specified string, returns -1 if no such occurrence is found. Same as AmiScript method strIndexOf() with one argument.

Parameter Definition

Name Type Description
to_find String  string to find

Example 1

1
2
3
4
5
6
String s = "3forge";
s.indexOf("forge");
s.indexOf("hello");

// s.indexOf("forge") = 1
// s.indexOf("hello") = -1

indexOf(to_find,start_index)

Integer String::indexOf(String to_find, Integer start_index)

Description

Returns the index within this string of the first occurrence of the specified string, starting from a specific index, returns -1 if no such occurrence is found. Same as AmiScript method strIndexOf() with two arguments.

Parameter Definition

Name Type Description
to_find String  string to find
start_index Integer  index to begin

Example 1

1
2
3
4
5
6
String s = "3forge:3forge";
s.indexOf("3forge",0);
s.indexOf("3forge",1);

// s.indexOf("3forge",0) = 0
// s.indexOf("3forge",1) = 7

is()

Boolean String::is()

Description

Returns "true" if the string contains characters other than whitespace characters, such as tabs, newlines, and spaces; returns "false" otherwise. Same as strIs(). Opposite of isnt().

Example 1

1
2
3
4
String s = "3forge";
s.is();

// s.is() = true

Example 2

1
2
3
4
String s = "  ";
s.is();

// s.is() = false

isEmpty()

Boolean String::isEmpty()

Description

Returns "true" if, and only if, length() is 0 (i.e, an empty string).

Example 1

1
2
3
4
5
String s1 = "3forge";
String s2 = "";

// s1.isEmpty() = false
// s2.isEmpty() = true

isnt()

Boolean String::isnt()

Description

Returns "true" if the string contains only the following whitespace characters: tabs, newlines, and spaces; return "false" otherwise. Same as strIsnt(). Opposite of is().

Example 1

1
2
3
4
String s = "3forge";
s.isnt();

// s.isnt() = false

Example 2

1
2
3
4
String s = "  ";
s.isnt();

// s.isnt() = true

lastIndexOf(to_find)

Integer String::lastIndexOf(String to_find)

Description

Returns the index within this string of the last occurrence of the specified string, returns -1 if not found. This method is case sensitive, to ignore case use the other lastIndexOf() method and set the ignore case flag. Also equivalent to AmiScript method strLastIndexOf().

Parameter Definition

Name Type Description
to_find String  string to find

Example 1

1
2
3
4
5
6
String s = "3forge";
s.lastIndexOf("3f");
s.lastIndexOf("3F");

// s.lastIndexOf("3f") = 0
// s.lastIndexOf("3F") = -1

lastIndexOf(to_find,last,ignore_case)

Integer String::lastIndexOf(String to_find, Integer last, Boolean ignore_case)

Description

Returns the index within this string of the last occurrence of the specified string by searching from the specified index backwards. Returns -1 if not found. Same as AmiScript method strLastIndexOf(), with a suppliable ignore case flag.

Parameter Definition

Name Type Description
to_find String  string to find
last Integer  index to begin
ignore_case Boolean  "true" if ignore case, "false" otherwise.

Example 1

1
2
3
4
5
6
7
8
String s = "3forge:3forge";
s.lastIndexOf("3F",7,true);
s.lastIndexOf("3F",6,true);
s.lastIndexOf("3F",6,false);

// s.lastIndexOf("3F",7,true) = 7
// s.lastIndexOf("3F",6,true) = 0
// s.lastIndexOf("3F",6,false) = -1

length()

Integer String::length()

Description

Returns the length of this string. Same as AmiScript method strLen().

Example 1

1
2
3
4
String s = "3forge";
s.length();

// s.length() = 6

replaceAll(to_replace,replacement)

String String::replaceAll(String to_replace, String replacement)

Description

Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence. Same as AmiScript method strReplace().

Parameter Definition

Name Type Description
to_replace String  string to find
replacement String  string replacement

Example 1

1
2
3
4
String s = "3 Forge";
s.replaceAll("3 F","3f");

// s.replaceAll("3 F","3f") = 3forge

splice(start,charsToReplace,replacement)

String String::splice(Number start, Number charsToReplace, String replacement)

Description

Replaces a base string's subsequence of chars with a replacement string. If start or charsToReplace extend beyond string limits, they will be set to string limits. Same as strSplice().

Parameter Definition

Name Type Description
start Number  zero indexed start of replacement.
charsToReplace Number  length of chars to replace.
replacement String  text to replace specified subsequence with, null is treated as empty string.

Example 1

1
2
3
4
String s = "3 Forge";
s.splice(0,3,"3f");

// s.splice(0,3,"3f") = 3forge

Example 2

1
2
3
4
String s = "3 forge";
s.splice(100,1," limit");

// s.splice(100,1," limit") = 3 forge limit

Example 3

1
2
3
4
String s = "3 forge";
s.splice(1,1,null);

// s.splice(1,1,null) = 3forge

split(delimiter)

List String::split(String delimiter)

Description

Returns a list of strings, split by the given delimiter.

Parameter Definition

Name Type Description
delimiter String  delimiter to split by

Example 1

1
2
3
4
String s = "Crouton, Artemis, Reggie";
s.split(", ");

// s.split(", ") = [Crouton, Artemis, Reggie]

splitLines()

List String::splitLines()

Description

Splits lines and returns a list of lines separated by line feed and line return chars.

Example 1

1
2
3
4
5
6
String s = "Crouton 
 Reggie 
 Artemis";
s.splitLines();

// s.splitLines() = [Crouton ,  Reggie ,  Artemis]

startsWith(s,ignore_case)

Boolean String::startsWith(String s, Boolean ignore_case)

Description

Tests if this string starts with the specified prefix. Same as AmiScript strStartsWith().

Parameter Definition

Name Type Description
s String  string to find
ignore_case Boolean  "true" to ignore case, "false" otherwise

Example 1

1
2
3
4
String s = "3forge";
s.startsWith("3F",true);

// s.startsWith("3F",true) = true

startsWith(s,start,ignore_case)

Boolean String::startsWith(String s, Integer start, Boolean ignore_case)

Description

Tests if this string starts with the specified prefix, starting from the given index.

Parameter Definition

Name Type Description
s String  string to find
start Integer  index to start
ignore_case Boolean  "true" to ignore case, "false" otheriwse

Example 1

1
2
3
4
String s = "3forge";
s.startsWith("3f",0,false);

// s.startsWith("3f",0,false) = true

strip(prefix,suffix)

String String::strip(String prefix, String suffix)

Description

Same as AmiScript method strStrip(). Returns the substring of supplied text with the prefix and suffix removed. If the string doesn't start with the specified prefix, then the prefix is ignored. If the string doesn't end with suffix, then the suffix is ignored.

Parameter Definition

Name Type Description
prefix String  The prefix to strip
suffix String  The suffix to strip

Example 1

1
2
3
4
String s = "3forge";
s.strip("3","");

// s.strip("3","") = forge

substring(begin)

String String::substring(Integer begin)

Description

Returns a string that is a substring of this string, starting from the specified index to the end of the string.

Parameter Definition

Name Type Description
begin Integer  index to begin

Example 1

1
2
3
4
String s = "3forge";
s.substring(1);

// s.substring(1) = forge

substring(begin,end)

String String::substring(Integer begin, Integer end)

Description

Returns a string that is a substring of this string, start and end at specific index. Same as AmiScript strSubstring().

Parameter Definition

Name Type Description
begin Integer  index to begin
end Integer  index to end

Example 1

1
2
3
4
String s = "3forge";
s.substring(1,6);

// s.substring(1,6) = forge

toJson()

String Object::toJson()

Description

Returns a string of a json representation of this object.

Example 16

1
2
3
4
String s = "3forge";
s.toJson();

// s.toJson() = "3forge"

toLower()

String String::toLower()

Description

Converts all of the characters in this String to lower case using the rules of the default locale. Same as AmiScript strLower().

Example 1

1
2
3
4
String s = "3FORGE";
s.toLower();

// s.toLower() = 3forge

toUpper()

String String::toUpper()

Description

Converts all of the characters in this String to upper case using the rules of the default locale. Same as AmiScript strUpper().

Example 1

1
2
3
4
String s = "3forge";
s.toUpper();

// s.toUpper() = 3FORGE

trim()

String String::trim()

Description

Returns a string whose value is this string, with any leading and trailing whitespace removed. Same as strTrim().

Example 1

1
2
3
4
String s = "   3forge   ";
s.trim();

// s.trim() = 3forge