From 98b81252b78f9cbc51941b369819d829d5f1f92c Mon Sep 17 00:00:00 2001 From: BigBlack <840206@qq.com> Date: Fri, 27 Dec 2019 12:20:06 +0800 Subject: [PATCH] fix #3217 (string.replace) --- vlib/builtin/string.v | 2 +- vlib/builtin/string_test.v | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index 04c282cf08..8a44b4b300 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -152,7 +152,7 @@ pub fn (s string) replace(rep, with string) string { break } idxs << idx - idx++ + idx += rep.len } // Dont change the string if there's nothing to replace if idxs.len == 0 { diff --git a/vlib/builtin/string_test.v b/vlib/builtin/string_test.v index 1c7b0336b5..b2fbbd0acc 100644 --- a/vlib/builtin/string_test.v +++ b/vlib/builtin/string_test.v @@ -220,6 +220,9 @@ fn test_replace() { assert b.replace('charptr', 'byteptr') == '*byteptr' c :='abc' assert c.replace('','-') == c + v :='a b c d' + assert v.replace(' ',' ') == 'a b c d' + } fn test_replace_each() {