Some important considerations when dealing with string functions in age
Tags: considerations, methods, string, apacheage
Published: 2023-08-11 06:58:12

In the last 2 articles I explained on how the string functions work and how can a string be manipulated using those functions. We discussed several functions like trim, ltrim, rtrim, tostring e.t.c. Each one of these functions have their unique important points that needs to be addressed. 

# Unique Considerations:
Each of the considerations are unique and important when dealing with that method.

## Replace
### Syntax: 
`replace(originalString, searchString, replaceString)`

Since we saw the above syntax for replace method. 
- In the syntax if any of the argument is null, the method will return null.
- If searchString is not located in the original string, the method will return the original string.

## Split
### Syntax: 
`split(originalString, splittingParameter)`

Since we saw the above syntax for split method.
- In the method if any of the argument is null the method will return null. Let's take a sample example: split(null, ',') and split(originalString, null) both the statements will be returned as null.

## left
### Syntax:
`left(originalString, length)`

- In above syntax if the parameter originalString is null the method will return null. For example if the method is of the form left(null, length) will return null.
- Meanwhile if we have the form of left(original, null) it will display an error. 
- If the above syntax has form left(null, null), the method will return null.
- The length integer number should be positive else if it is not a positive integer an error will be returned. 
- If length exceeds the size of originalString, the same originalString will be returned.

## Right
### Syntax:
`right(originalString, length)`

- In above syntax if the originalString is null and the method is of the form right(null, length), the method will return null.
- If the method is of the form right(null, null) i.e. both originalString and length are null, the method will return null as well.
- The form of above method, right(originalString, null) will throw an error. 
- The length integer number should be positive else if it is not a positive integer an error will be returned. 
- If length exceeds the size of originalString, the same originalString will be returned.

## SubSting
### Syntax:
`subString(originalString, start [, length])`

- In above syntax the start variable will use zero based index.
- If in above syntax the length variable is not defined the method will return a substring starting at the position defined by the start variable and extending till the end of the original.
- If the originalString is null, the method returns null.
- If the start variable is not defined or is a negative number the method throws an error.
- If the length variable is not defined or is a negative number the method throws an error.
- If the start variable is zero the substring to be returned will start at the beginning of the original.
- If the length is defined as zero, the method will return an empty string. 

## rTrim
### Syntax:
`rTrim(originalString)`

- The method will always return null if the originalString parameter is null i.e. of the form: rTrim(null).

## lTrim
### Syntax:
`lTrim(originalString)`

- The method will always return null if the originalString parameter is null i.e. of the form: lTrim(null).

## Trim
### Syntax:
`trim(originalString)`

- The method will always return null if the originalString parameter is null i.e. of the form: Trim(null).

## toLower
### Syntax:
`toLower(originalString)`

- The method will always return null if the originalString parameter is null i.e. of the form: toLower(null).

## toUpper
### Syntax:
`toUpper(originalString)`

- The method will always return null if the originalString parameter is null i.e. of the form: toUpper(null).

## reverse
### Syntax:
`reverse(originalString)`

- The method will always return null if the originalString parameter is null i.e. of the form: reverse(null).

## toString
### Syntax:
`toString(originalString)`

- The method will always return null if the originalString parameter is null i.e. of the form: toString(null).
- If the expression is already a string it will be returned as it is, i.e. not changed.

## References:
You can view more on GitHub and documentation of Apache age by following these links:

1. https://age.apache.org/age-manual/master/intro/overview.html
2. https://github.com/apache/age
3. https://dev.to/talhahahae/numeric-functions-in-apache-age-34ga
4. https://dev.to/talhahahae/logarithmic-functions-1nbl
5. https://age.apache.org/age-manual/master/functions/string_functions.html
6. https://dev.to/talhahahae/string-functions-in-age-268j
7. https://dev.to/talhahahae/string-functions-in-age-part-2-1jip