String Expressions

Basics

String Expressions are functions you can call within code segments in Soley Studio. They combine string values with string operations. This article contains string expressions in a table.  Furthermore, at the end of the article a code example is provided.

Table of string expressions

The table contains the function syntax on the left hand side, as well as a brief description on the right hand side.

Syntax Description
.length() Gives back the length of the string as int
.startsWith(strToSearchFor) Gives back whether the string starts with “strToSearchFor”, as boolean
.endsWith(strToSearchFor) Gives back whether the string ends with “strToSearchFor”, as boolean
.indexOf(strToSearchFor) Gives back the position of the first appearance of “strToSearchFor” as integer, or -1 if not found
.indexOf(strToSearchFor, int) Gives back the position of the first appearance of “strToSearchFor” as integer when starting the search at position “int”, or -1 if not found
.lastIndexOf(strToSearchFor) Gives back the position of the last appearance of “strToSearchFor” as integer, or -1 if not found
.lastIndexOf(strToSearchFor, int) Gives back the position of the last appearance of “strToSearchFor” as integer when starting the search at position “int”, or -1 if not found
.substring(startIndex) Gives back substring from “startIndex” (int) on (of full remaining length)
.substring(startIndex, length) Gives back substring of the length “length” (int) and starting at position “startIndex” (int)
.replace(startIndex, length, replaceStr) Replaces the substring starting at position “startIndex” (int) of length “length” (int) with the string “replaceStr”
.toLower() Gives back a lowercase version of the string
.toUpper() Gives back a uppercase version of the string
.asArray(separator) Gives back an array of substrings separated by the “separator” (string)

In case you couldn’t find the right function for your needs, have a look at the other ones in this article.

Code Example

1  n.str == "foo bar foo"
2  n.str.length()==11
3  n.str.startsWith("foo")==true
4  n.str.endsWith("foo")==true
5  n.str.indexOf("foo")==0
6  n.str.indexOf("foo", 1)==8
7  n.str.lastIndexOf("foo")==8
8  n.str.substring(4,3)=="bar"
9  n.str.substring(4)=="bar foo"
10 n.str.replace(4,3,"foo")=="foo foo foo"
11 n.str.toUpper()=="FOO BAR FOO"
12 n.str.asArray(" ")==array<string>["foo","bar","foo"]

Was this article helpful?

Related Articles