NCL Home >
Documentation >
Functions >
String manipulation
replaceSingleChar
Within a string replace one character with another character. (Deprecated: see str_sub_str.)
Prototype
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" ; This library is automatically loaded ; from NCL V6.2.0 onward. ; No need for user to explicitly load. function replaceSingleChar ( x [*] : string, oldC [1] : string, newC [1] : string ) return_val : string
Arguments
xA single string or a one dimensional array of strings.
oldCThe single character to be replaced.
newCThe single character which will be substituted.
Return value
A string of the same size as x.
Description
This function has been deprecated in version 5.1.1. Use str_sub_str instead.
Change all occurrences of a specific character to another. This is case sensitive.
See Also
Examples
Example 1
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" s = "apples are good" replaceSingleChar( s1, " ", "_") print(s) S = (/ "Pears are even better!","NCEP 1950-1999"/) replaceSingleChar( S, " ", "_") print(S) replaceSingleChar( S, "!", "$") print(S)procudes
(0) apples_are_good (0) Pears_are_even_better! (1) NCEP_1950-1999 (0) Pears_are_even_better$ (1) NCEP_1950-1999