Skip to main content
NICE CXone Expert
Expert Success Center

String functions

These string functions are part of the DekiScript and Expert runtime environment.

string.cast(value) : str

Cast value to a string or nil if not possible.

Name Type Description
value any value to cast
var string = "27";
let string = num.cast(string);
let num = (string - 12);
num;

string.compare(first, second, ignorecase) : num

Compare two strings.

Name Type Description
first str first string value
second str second string value
ignorecase bool (optional) ignore case (default: false)

 

Compare the first string to the second string

var first = "MindTouch";
var second = "Touch";
if (string.compare(first,second))
{
    "The first string is different than the second";
}
else
{
    "The first string is Exactly the same as the second";
}

string.contains(first, second, ignorecase) : bool

Check if the first string contains the second string.

Name Type Description
first str first string value
second str second string value
ignorecase bool (optional) ignore case (default: false)


See if FIRST contains SECOND while ignoring the case

if (string.contains("MindTouch","mind",true)) {
    "Match!";
} else {
    "One does not contain the other";
}

string.deserialize(value) : any

Convert a string into a value.

Name Type Description
value str string value

string.endswith(first, second, ignorecase) : bool

Check if the first string ends with the second string.

Name Type Description
first str first string value
second str second string value
ignorecase bool (optional) ignore case (default: false)

string.equals(first, second, ignorecase) : bool

Determine equality of two strings

Name Type Description
first str first string value
second str second string value
ignorecase bool (optional) ignore case (default: false)

string.escape(value) : str

Escape special characters in string.

Name Type Description
value str string value

string.eval(code, ignoreErrors) : any

Evaluate a dekiscript expression.

Name Type Description
code str dekiscript expression
ignoreErrors bool (optional) ignore errors during evaluation

string.format(text, values) : str

Replaces placeholders with values in a string.

Name Type Description
text str string with placeholders
values any (optional) values to insert into string

The follow table shows argument combinations and their outcomes.

Text Values Result
nil   nil
""   ""
"HI $0!" [ "Bob", "Charles" ] "Hi Bob!"
"HI $first!" { first: "Bob", second: "Charles" } "Hi Bob!"

 

string.hash(value) : str

Compute MD5 hash of string.

Name Type Description
value str string value


Create a variable and MD5 hash it

var hashvar = "This is important";
string.hash(hashvar);

string.indexesof(first, second, ignorecase) : list

Get all indexes of the second string in the first string.

Name Type Description
first str first string value
second str second string value
ignorecase bool (optional) ignore case (default: false)

string.indexof(first, second, ignorecase) : num

Get index of the second string in the first string.

Name Type Description
first str first string value
second str second string value
ignorecase bool (optional) ignore case (default: false)

string.insert(first, second, index) : str

Insert the second string into the first string at the specified index.

Name Type Description
first str first string value
second str second string value
index num insert position

string.iscontrol(value) : bool

Check if first character in string is a control character.

Name Type Description
value str string value

string.isdigit(value) : bool

Check if first character in string is a decimal digit.

Name Type Description
value str string value

string.ishighsurrogate(value) : bool

Check if first character in string is a high surrogate (UTF-32).

Name Type Description
value str string value

string.isletter(value) : bool

Check if first character in string is an alphabetic character.

Name Type Description
value str string value

string.isletterordigit(value) : bool

Check if first character in string is an alphabetic character or decimal digit.

Name Type Description
value str string value

string.islower(value) : bool

Check if first character in string is a lowercase letter.

Name Type Description
value str string value

string.islowsurrogate(value) : bool

Check if first character in string is a low surrogate (UTF-32).

Name Type Description
value str string value

string.isnumber(value) : bool

Check if first character in string is a number.

Name Type Description
value str string value

string.ispunctuation(value) : bool

Check if first character in string is a punctation mark.

Name Type Description
value str string value

string.isseparator(value) : bool

Check if first character in string is a separator character.

Name Type Description
value str string value

string.issurrogate(value) : bool

Check if first character in string is a surrogate character (UTF-32).

Name Type Description
value str string value

string.issymbol(value) : bool

Check if first character in string is a symbol character.

Name Type Description
value str string value

string.isupper(value) : bool

Check if first character in string is an uppercase letter.

Name Type Description
value str string value

string.iswhitespace(value) : bool

Check if first character in string is white space.

Name Type Description
value str string value

string.join(list, separator) : str

Join strings in a list using a specified separator.

Name Type Description
list list list of strings
separator str (optional) separator used between strings (default: ", ")
var lst = ["one","two","three","four","five"];
string.join(lst,",");

string.lastindexof(first, second, ignorecase) : num

Get last index of the second string in the first string.

Name Type Description
first str first string value
second str second string value
ignorecase bool (optional) ignore case (default: false)

string.length(text) : num

Get the length of the string.

Name Type Description
text str (optional) string value

string.match(text, pattern, ignorecase, withIndex) : any

Match a string against a regular expression pattern and return the first match.

Name Type Description
text str string value
pattern str regular expression pattern
ignorecase bool (optional) ignore case (default: false)
withIndex bool (optional) return text with index (default: false)

string.matches(text, pattern, ignorecase, withIndex, captures) : list

Match a string against a regular expression pattern and return all matches.

Name Type Description
text str string value
pattern str regular expression pattern
ignorecase bool (optional) ignore case (default: false)
withIndex bool (optional) return text with index (default: false)
captures bool (optional) return capture groups instead of matched text (default: false)

string.matchreplace(text, pattern, replacement, ignorecase) : str

Replace every match the regular expression pattern with replacement value.

Name Type Description
text str string value
pattern str regular expression pattern
replacement str replacement value
ignorecase bool (optional) ignore case (default: false)

string.nbsp : str

Non-breakable space.

string.nbsp;  // Parenthesis not needed

string.padleft(text, width, padding) : str

Pad string with characters on the left until it reaches the specified width.

Name Type Description
text str string value
width num total width (negative: relative to current length; positive: absolute length)
padding str (optional) padding character (default: " ")

string.padright(text, width, padding) : str

Pad string with characters on the right until it reaches the specified width.

Name Type Description
text str string value
width num total width (negative: relative to current length; positive: absolute length)
padding str (optional) padding character (default: " ")

string.quote(text) : str

Quote string and escape characters.

Name Type Description
text str string value

string.remove(text, index, count) : str

Remove characters from a string the specified index.

Name Type Description
text str string value
index num index to remove characters at
count num (optional) number of characters to remove (default: all)

string.replace(text, before, after, ignorecase) : str

Replaces all occurrences of a string with another string.

Name Type Description
text str string value
before str old value
after str new value
ignorecase bool (optional) ignore case (default: false)

string.searchescape(value) : str

Escape special characters in string.

Name Type Description
value str string value

string.serialize(value) : str

Convert a value into a string.

Name Type Description
value any (optional) value

string.split(text, separator, max) : list

Split string at each occurrence of the separator up to the specified limit.

Name Type Description
text str string value
separator str string separator
max num (optional) maximum results (default: no limit)


Split a string into a list and output it in a formatted <pre> tag

var brothers = "Marky, Ricky, Danny, Terry, Mikey, Davey, Timmy, Tommy, Joey, Robby, Johnny, Brian";
var lst = string.split(brothers,',',5);
web.pre(lst);

string.splitcsv(text) : map

Convert string into a collection of rows and columns.

Name Type Description
text str comma separated values


Prepare a comma separated string for .CSV format

var brothers = "Marky, Ricky, Danny, Terry, Mikey, Davey, Timmy, Tommy, Joey, Robby, Johnny, Brian";
var lst = string.splitcsv(brothers);
web.pre(lst);

string.sqlescape(value) : str

Escape special SQL characters in string.

Name Type Description
value str string value

string.startswith(first, second, ignorecase) : bool

Check if the first string starts with the second string.

Name Type Description
first str first string value
second str second string value
ignorecase bool (optional) ignore case (default: false)

string.substr(text, start, length) : str

Extract a substring.

Name Type Description
text str string value
start num sub-string start index
length num (optional) sub-string length (default: remainder of string)


Extract the word Customer Success 

var str = "MindTouch Customer Success Center";
string.substr(str,10,16);

string.tocamelcase(text) : str

Convert first charater of each word in string to uppercase.

Name Type Description
text str string value
var str = "here is my text, it is all lowercase";
string.tocamelcase(str);

string.tolower(text) : str

Convert string to lowercase characters.

Name Type Description
text str string value
var str = "THIS IS REALY LOUD!";
string.tolower(str);

string.tolowerfirst(text) : str

Convert first character in string to lowercase.

Name Type Description
text str string value
var str = "THIS IS REALY LOUD!";
string.tolowerfirst(str)

string.toupper(text) : str

Convert string to uppercase characters.

Name Type Description
text str string value

string.toupperfirst(text) : str

Convert first character in string to uppercase.

Name Type Description
text str string value

string.trim(text) : str

Remove whitespace from the beginning and end of the string.

Name Type Description
text str string value

string.trimend(text) : str

Remove whitespace from the end of the string.

Name Type Description
text str string value

string.trimstart(text) : str

Remove whitespace from the beginning of the string.

Name Type Description
text str string value

 

  • Was this article helpful?