diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index 1a4815dc2b..ebe3b33ecc 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -739,12 +739,12 @@ fn (s string) index_kmp(p string) int { // index_any returns the position of any of the characters in the input string - if found. pub fn (s string) index_any(chars string) int { - for c in chars { - idx := s.index_(c.ascii_str()) - if idx == -1 { - continue + for i, ss in s { + for c in chars { + if c == ss { + return i + } } - return idx } return -1 } diff --git a/vlib/builtin/string_test.v b/vlib/builtin/string_test.v index 5936aff5f0..b3105dbce0 100644 --- a/vlib/builtin/string_test.v +++ b/vlib/builtin/string_test.v @@ -910,3 +910,9 @@ fn test_string_to_rune() { x := 'Hello World 👋' assert x.runes().len == 13 } + +fn test_index_any() { + x := 'abcdefghij' + assert x.index_any('ef') == 4 + assert x.index_any('fe') == 4 +}