# System Functions

SUB( ) | Substitute Text

## Format

SUB(string$,search$,replace$[,instance])[,ERR=stmtref])
Where:

instance | Optional. Integer. Which occurrence to find:
0 | All occurrences (assumed, if not given).
> 0 | Specific occurrence, searching left to right within string$; i.e. 1 = first occurrence, 2 = second occurrence, etc.
< 0 | Specific occurrence from end of string$, searching from left to right; i.e. -1 = first occurrence from end of string$, -2 = second occurrence from end of string$, etc.
search$ | Value for which to search. String expression. Cannot be null. |
replace$ | Text to replace the original search text, if found. String expression. You must include a replace value; however, the value can be null; e.g. sub(A$,B$,"",0,err=100). |
stmtref | Program line number or statement label to which to transfer control. |
string$ | String expression containing the string in which to search-and-replace and perform the substitution. |

## Returns

Converted string.

## Description

The SUB( ) function performs a substitution within a string. The search value cannot be null. (That generates an Error #46: Length of string invalid.) If no substitutions occur, no error is generated.

## Example

print 'CS';
list
A$="Hello there",B$="e",Z$=sub(A$,B$,"",0)
print Z$+" "+A$
end
->run
Hllo thr Hello there