Search the Community
Showing results for tags 'replacecharacterinstring'.
-
Hi All, I have written a UDF for one of my requirement which replaces a single character in string with a sub string/another character. I am using this for my requirement by calling below function as StrReplace("C:\Software\Autoit\Substr","\","\\") and gives result as C:\\Software\\Autoit\\Substr Please let me know if this can be improvised or any mistakes to correct. ;=============================================================================== ; ; Function Name: StrReplace($INPUT_STRING) ; Description: This function is to replace a character with another in a string. ; Parameter(s): $INPUT_STRING - Original String Value ; $STR_2_FIND - Single Character to find the $INPUT_STRING ; $STR_2_REPLACE - Substring/Multiple Characters to replace in place of $STR_2_FIND value ; Requirement(s): Replacing one single Character in a string with multiple Characters ; Return Value(s): success - Output string after replacing a character with required character ; failure - 0 ; Author(s): smartkey ; ;=============================================================================== Func StrReplace($INPUT_STRING, $STR_2_FIND, $STR_2_REPLACE) Local $OUTPUT_STRING = "" If StringLen($INPUT_STRING) > 0 Then If StringMid($INPUT_STRING,1,1) = $STR_2_FIND Then $OUTPUT_STRING = $OUTPUT_STRING & $STR_2_REPLACE Else $OUTPUT_STRING = StringMid($INPUT_STRING,1,1) EndIf For $i=2 to StringLen($INPUT_STRING) If StringMid($INPUT_STRING,$i,1) = $STR_2_FIND Then $OUTPUT_STRING= $OUTPUT_STRING & $STR_2_REPLACE Else $OUTPUT_STRING= $OUTPUT_STRING & StringMid($INPUT_STRING,$i,1) EndIf Next Return $OUTPUT_STRING Else Return 0 EndIf EndFunc
- 2 replies
-
- stringreplace
- stringmanipulate
-
(and 1 more)
Tagged with: