# trim() function

The trim() function removes leading,
trailing, and/or redundant characters from a string.

## Syntax

```
trim(str.exp, {trimchar{,type}})
```

## Parameter(s)

| str.exp | String from which the specified characters are removed. |
| --- | --- |
| trimchar | Specifies the specific leading, trailing, or redundant character to trim. If specified, then that character substitutes for the space. |
| type | If specified, then the trim() behavior can be controlled more specifically. If not specified, then type R is assumed. Available values are: |
| A | Trim all. |
| B | Trim leading and trailing. |
| L | Trim leading. |
| T | Trim trailing. |
| R | Trim redundant. |

## Description

If only one parameter is specified, trim() removes all leading and trailing spaces from a string
expression, and compresses multiple embedded spaces to one embedded
space.

## Example(s)

After trimming, string contains: `"cat dog bird"`.

```
string = trim(" cat dog bird ")
```
In this case, the trim() function is
used to convert fixed length fields to variable length fields by removing
trailing and leading spaces.

```
readt record else stop
name = trim(record[1,25])
address = trim(record[26,40])
```
The program:

```
line = ’--a--b--c--’
print trim(line,’-’)
print trim(line,’-’,’L’)
print trim(line,’-’,’T’)
print trim(line,’-’,’B’)
print trim(line,’-’,’A’)
print trim(line,’-’,’R’)
```
produces the output:

```
-a-b-c
a--b--c--
--a--b--c
a--b--c
abc
-a-b-c-
```

## See also

- [BASIC functions](https://d3codex.com/pickbasic-flashbasic/basic-functions/)
- [Statements and functions](https://d3codex.com/pickbasic-flashbasic/statements-and-functions/)

---
Source: https://d3codex.com/pickbasic-flashbasic/trim-function/ - part of the D3Codex reference.
