# strreplace

Replaces a string, with another string. (version 4.67 or later)

## Format

    strreplace <strvar> <index> <regex> <newstr>

## Remarks

Replaces a specified <regex> string in the string variable <strvar> beginning at a specified position <index>(1-origin), with another specified <newstr> string.
If the <newstr> is ''(empty), the <regex> string is removed from <strvar>.

When the replacing succeeds, the system variable "result" is set to 1 and the matched string by the <regex> is stored into the system variable "matchstr".
When the replacing fails by the reason <regex> not match <strvar>, the system variable "result" is set to 0.
When <regex> format is not valid, the system variable "result" is set to -1.

When a user searches the multi-byte string like as Japanese, the user must configure the regular encoding by using the regexoption previously.

NOTE: When this macro command is performed, the 9 system variables from "groupmatchstr1" to "groupmatchstr9" are cleared.

## Example

    src='linux.txt'
    strreplace src 1 '\.txt' '.doc'
    messagebox src 'result'          ; linux.doc

    src='I can do it.'
    strreplace src 1 'can\s' ''
    messagebox src 'result'     ; 'I do it.'

    src='Microsoft Windows XP [Version 5.1.2600]'
    strmatch src '(Version \d+.\d+.)\d+'

    int2str s result
    messagebox s groupmatchstr1
    pos=result                ; 23
    mstr=groupmatchstr1       ; Version 5.1.

    strreplace src pos mstr 'Build '
    if result=1 then
    	messagebox src 'result'   ; Microsoft Windows XP [Build 2600]
    endif

## See also

- Oniguruma Regular Expressions
- regexoption
- strmatch
- strinsert
- strremove