# Trim

Values sometimes have spaces at the start or end because of mistakes in data entry or the use of a split operation to break apart a CSV (comma separated list). These aren't always easily visible but can cause problems if you're trying to do exact matches for a [Lookup/Join](https://github.com/concentra-analytics/working-with-data/tree/51c414aad5b91e0da2741a07a436476e362ed6ce/strings/General/Join.md). Trim allows you to strip out trailing or leading characters (usually white space by default) to clean up your text field.

## Excel

\=\~TRIM!\~(‹string›)

```
=TRIM(A1) // " Recruiter " -> "Recruiter"
```

## Tableau

Tableau supports three `TRIM()` operations:

* \~TRIM!\~(‹string›) removes leading and trailing spaces&#x20;
* \~LTRIM!\~(‹string›) removes leading spaces only
* \~RTRIM!\~(‹string›) removes trailing spaces only

```
TRIM([Job Role]) // " Recruiter " -> "Recruiter"
```

```
LTRIM([Job Role]) // " Recruiter " -> "Recruiter "
```

```
RTRIM([Job Role]) // " Recruiter " -> " Recruiter"
```

## Alteryx

Alteryx supports three `TRIM()` operations:

* \~TRIM!\~(‹within\_string›«, target\_string») removes leading and trailing characters
* \~TRIMLEFT!\~(‹within\_string›«, target\_string») removes leading characters only
* \~TRIMRIGHT!\~(‹within\_string›«, target\_string») removes trailing characters only

```
TRIM([Job Role]) // " Recruiter " -> "Recruiter"
```

```
TRIMLEFT([Job Role]) // " Recruiter " -> "Recruiter "
```

```
TRIMRIGHT([Job Role]) // " Recruiter " -> " Recruiter"
```

NB. If «target\_string» is excluded, the default behaviour is to trim whitespace. If it is included, you can specify what character to trim:

```
TRIM([Job Coded], "*") // "**HR014**" -> "HR014"
```

## OrgVue

Gizmo does not support `Trim` operations, although OrgVue workspace will usually trim strings by default.

## tSQL

* \~LTRIM!\~(‹string›) removes leading spaces only
* \~RTRIM!\~(‹string›) removes trailing spaces only
* To remove leading *and* trailing spaces, use \~RTRIM!\~(\~LTRIM!\~(‹string›))

```
SELECT LTRIM(JobRole) AS JobRole
FROM EmployeesData
-- " Recruiter " -> "Recruiter "
```

```
SELECT RTRIM(JobRole) AS JobRole
FROM EmployeesData
-- " Recruiter " -> " Recruiter"
```

```
SELECT RTRIM(LTRIM(JobRole)) AS JobRole
FROM EmployeesData
-- " Recruiter " -> "Recruiter"
```

## Python

‹string›.\~strip(«target\_string»)!\~

```
jobRole.strip() # " Recruiter " -> "Recruiter"
# OR
jobCode.strip('*') # " HR014**" -> " HR014"
```

NB.

* If «target\_string» is excluded, the default behaviour is to trim whitespace.&#x20;
* If «target\_string» is included, you can specify what character to trim.&#x20;
* The above examples assume variables have been declared for `jobRole` and `jobCode`. For more information, go to [General > Variables](https://orgvue.gitbooks.io/formula-translator/content/general/variables.html).
