< Day Day Up > |
Replace()Category: Text Syntax: Replace ( text ; startingAt ; numberOfCharacters ; replacementText ) Parameters: text ”any expression that resolves to a text string; startingAt ”any positive number or expression that returns a positive number; numberOfCharacters ”any positive number or expression that returns a positive number; replacementText ”any expression that resolves to a text string. Description: The Replace() function extracts a segment of a text string and replaces it with some other string. The segment to extract begins with the startingAt character number and extends for numberOfCharacters . The replacement string is specified by the replacementText parameter. The extracted segment and the replacement text do not need to be the same length. Examples: Replace ("abcdef"; 4; 2; "TEST") Returns abcTESTf . Replace ("Fred Smith" ; 1 ; 4 ; "Joe") Returns Joe Smith . Comments: The Replace() and Substitute() functions are often confused with one another. Substitute() replaces all occurrences of a particular substring with another string, whereas Replace() replaces a specified range of characters with another string. Replace() is often used for manipulation of delimited text arrays. There is no function that will directly replace the contents of a particular item in an array with another. The Replace() function can do this by finding the appropriate delimiters and inserting the replacement item. For instance, if you have the a pipe-delimited list of numbers (for example, 3488815043 ) and you wish to increase the third item in the list by 18, you could use the following formula: Let ([ item = 3; increase = 18; start = Position (myArray ; "" ; 1 ; (item-1)) + 1; end = Position (myArray; "" ; 1 ; item); itemValue = Middle (myArray ; start ; end-start); newValue = itemValue + increase ]; Replace (myArray ; start ; end-start ; newValue) ) Given the example string as myArray , this would produce the string 3488816843 . Typically, the item and increase values would be supplied by other fields and not hard-coded into the formula. |
< Day Day Up > |