Manipulating single characters inside a string?
Hello CF Experts,
I feel a little stupid having to ask this, but I might be suffering from mental block:
I need to manipulate single characters inside a string. Lets say I have a string "-----" (5 hyphens) and
I want to replace the hyphen at position #pos# with "X".
I tried using the Mid() function, but that apparently is read-only:
<cfset Mid(string,#pos#,1) = "X">
results in an error.
Of course I can do string concatenation like
<cfset string = Mid(string,1,#pos#-1) & "X" & Mid(string,#pos#+1,Len(string)-#pos#)
or use the Insert/RemoveChars functions:
<cfset string = Insert("X",string,#pos#-1)>
<cfset string = RemoveChars(string,#pos#+1,1)>
but this seems awfully awkward.
There must be a more elegant solution. Any hints?
Regards, Richard
