Skip to content
Reference > Methods

strSplice(text,start,charsToReplace,replacement)

Definition

String strSplice(String text, Number start, Number charsToReplace, String replacement)

Description

Given the base string, a 0-based index, the length of the replacement string, and the replacement string, modifies part of the base string at the index with the specified replacement string. If start or charsToReplace extends beyond string length, they will be set to string limits.

Parameter Definition

Name Type Description
text String The base string that will have a portion spliced with replacement text
start Number zero indexed start of replacement
charsToReplace Number length of chars to replace
replacement String text to replace specified subsequence with, null is treated as empty string

Examples

1
2
3
4
String r1 = strSplice("this is test",5,2,"was"); // r1 == this was test
String r2 = strSplice("this is test",5,2,null); // r2 == this  test
String r3 = strSplice("this is test",8,0,"inserted "); // r3 == this is inserted test
String r4 = strSplice("this is test",100,0," of limits"); // r4 == this is test of limits