# Text Functions

Learn how to use text functions in expressions in ActiveReportsJS.

## Content

### Contains
Returns a boolean value indicating whether a specified substring occurs within the calling string. This function performs a case-sensitive comparison.
**Syntax**
Contains(`str`, `substring`)
**Arguments**

* `str` - the string to inspect
* `substring` \- the string to seek\.

**Examples**
You can use the following expression to find out whether the current `ProductName` field value contains the `MP3` string.
```js
{Contains(ProductName, "MP3")}
```
### Len
Returns an integer value representing the length of a specified string. The length of a string is the number of characters it contains.
**Syntax**
Len(`str`)
**Arguments**

* `str` - the text string to measure.

**Examples**
You can use the following expression to find out the length of the current `productName` field value.
```js
{Len(productName)}
```
### EndsWith
Returns a boolean value indicating whether one text string ends with another. This function performs a case-sensitive comparison.
**Syntax**
EndsWith(`str1`, `str2`)
**Arguments**

* `str1` \- the text string to test\.
* `str2` \- the text string to search for at the end of `str1`..

**Examples**
You can use the following expression to find out whether the current `productName` field value ends with the `player` string.
```js
{EndsWith(productName, "player")}
```
### IndexOf
Returns the zero-based index of the first occurrence of one text string within another. The method returns -1 if the string is not found. This function performs a case-sensitive comparison.
**Syntax**
IndexOf(`str1`, `str2`, [`startIndex`])
**Arguments**

* `str1` \- the string being searched\.
* `str2` \- the string to seek\.
* `startIndex` \- an optional number indicating the search starting position

**Examples**
You can use the following expression to return the first whitespace's position in the current `productName` field value.
```js
{IndexOf(productName, " ")}
```
### InStr
Returns a number specifying the 1-based position of the first occurrence of one string within another.
**Syntax**
InStr(`str1`, `str2`)
**Arguments**

* `str1` \- the string being searched\.
* `str2` \- the string to seek\.

**Examples**
You can use the following expression to return the first whitespace's position in the current `productName` field value.

```js
{InStr(productName, " ")}
```

### LastIndexOf
Returns the zero-based index of the last occurrence of one text string within another. The method returns -1 if the string is not found. This function performs a case-sensitive comparison.
**Syntax**
LastIndexOf(`str1`, `str2`, [`startIndex`])

**Arguments**

* `str1` \- the string being searched\.
* `str2` \- the string to seek\.
* `startIndex` \- an optional number indicating the search starting position

**Examples**
You can use the following expression to return the last whitespace's position in the current `productName` field value.
```js
{LastIndexOf(productName, " ")}
```
### Replace
Returns a new string, in which a portion of a string of text is replaced with another string.
**Syntax**
Replace(`str`, `oldValue`, `newValue`)
**Arguments**

* `str` \- the string to operate on\.
* `oldValue` \- the string to be replaced\.
* `newValue` \- the string to replace all occurrences of `oldValue`.

**Examples**
You can use the following expression to remove all white spaces in the current `productName` field value.
```js
{Replace(productName, " ", "")}
```
### StartsWith
Returns a boolean value indicating whether one text string starts with another. This function performs a case-sensitive comparison.
**Syntax**
StartsWith(`str1`, `str2`)
**Arguments**

* `str1` \- the text string to test\.
* `str2` \- the text string to search for at the beginning of `str1`.\\

**Examples**
You can use the following expression to find out whether the current `productName` field value starts with the `TV` string.
```js
{StartsWith(productName, "TV")}
```
### Substring
Returns a substring from the specified string. The substring starts at a specified position and has a specified length.
**Syntax**
Substring(`str`, `startIndex`, [`length`])
**Arguments**

* `str` – the text string to extract a substring from
* `startIndex` \- the zero\-based starting position of a substring in the calling string\.
* `length` \- an optional number of characters in the substring\.

**Examples**
You can use the following expression to extract the substring starting from the first whitespace's position from the current `productName` field value.

```js
{Substring(productName, IndexOf(productName, " ") + 1)}
```
### ToLower
Returns a copy of the specified string converted to lower case.
**Syntax**
ToLower(`str`)
**Arguments**

* `str` – the text string to operate on

**Examples**
You can use the following expression to convert the current `productName` field value to lower case.
```js
{ToLower(productName)}
```
### ToUpper
Returns a copy of the specified string converted to upper case.
**Syntax**
ToUpper(`str`)
**Arguments**

* `str` – the text string to operate on

**Examples**
You can use the following expression to convert the current `productDescription` field value to upper case.
```js
{ToUpper(productDescription)}
```
### Trim
Returns a new string in which all leading and trailing white-space characters from the specified string are removed.
**Syntax**
Trim(`str`)
**Arguments**

* `str` – the text string to operate on

**Examples**
You can use the following expression to remove all leading and trailing white-space characters from the current value of the `productName` field.
```js
{Trim(productName)}
```
### TrimEnd
Returns a new string in which all trailing white-space characters from the specified string are removed.
**Syntax**
TrimEnd(`str`)
**Arguments**

* `str` – the text string to operate on

**Examples**
You can use the following expression to remove all trailing white-space characters from the current value of the `productName` field.
```js
{TrimEnd(productName)}
```
### TrimStart
Returns a new string in which all leading white-space characters from the specified string are removed.
**Syntax**
TrimStart(`str`)
**Arguments**

* `str` – the text string to operate on

**Examples**
You can use the following expression to remove all leading white-space characters from the current value of the `productName` field.

```js
{TrimStart(productName)}
```