Friday, November 2, 2018

Using REPLACE and SUBSTR for Formula functions

This article gives examples on using some common string functions that can be used for NetSuite search formulas via UI or script,
and custom formula fields.

REPLACE : Replaces a sequence of characters in a string with another set of characters.

Syntax: REPLACE(char, search_string[, replacement_string ])

Examples:

REPLACE('123123test', '123'); would return 'test'
REPLACE('123test123', '123'); would return 'test'
REPLACE('222test', '2', '3'); would return '333test'
REPLACE('0000123', '0'); would return '123'
REPLACE('0000123', '0', ' '); would return '    123'

--------------------

SUBSTR : Extract a substring from a string

Syntax : { SUBSTR | SUBSTRB | SUBSTRC | SUBSTR2 | SUBSTR4}(char, position [, substring_length ])

Note: Parameter 'position' can be a negative number, this will start from the end of the string and counts backwards.

Examples:

SUBSTR('This is a test', 6, 2) //returns 'is'
SUBSTR('This is a test', 6) //returns 'is a test'
SUBSTR('TheFoxIsBrown', 1, 3) //returns 'The'
SUBSTR('TheFoxIsBrown', 4, 3) //returns 'Fox'
SUBSTR('TheFoxIsBrown', -5, 5) //returns 'Brown'

2 comments: