- NAME
REPCHR()
- PURPOSE
Replace all occurrences of one character with another in a string.
- CALLING SEQUENCE
New_String = repchr( In_string, OldChar, [NewChar])
- INPUTS
in_string = original text string, scalar or array
OldChar = character to replace. If the OldChar contains
more than 1 character, only the first character is used.
- OPTIONAL INPUT
newchar = single character to replace it with.
The default is a single space
- OUTPUTS
new_string = same as in_string, but with all occurrences of old
replaced by newchar
- EXAMPLE
in_string = ['lettuce, tomato, grape']
print, repchr( in_string, ',') ;replace comma with space
'lettuce tomato grape'
- NOTES
Use REPSTR() to replace words rather than a single character
For a more sophisticated routine that allows regular expressions look
at MG_STRREPLACE() http://docs.idldev.com/idllib/strings/mg_streplace.html
Since IDL 8.4 one can use the .REPLACE() method for string variables
Note that REPCHR() is the fastest (though least versatile) of these routines,
because the length of the string never changes, allowing direct manipulation of
byte values.
- MODIFICATION HISTORY
Written W. Landsman April 2016
Adapted from similar code by R. Sterner JHUAPL Oct, 1986