# strreplace

Replaces a string, with another string.

## 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 result variable is 1 and the matched string by the <regex> is stored into the matchstr variable.
When the replacing fails, the result variable is 0.

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

## 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

## Reference

Oniguruma Regular Expressions
regexoption
strmatch
strinsert
strremove