diff --git a/builtin/string.v b/builtin/string.v index c7db31df53..54f93d0b79 100644 --- a/builtin/string.v +++ b/builtin/string.v @@ -771,6 +771,19 @@ fn (s[]string) join_lines() string { return s.join('\n') } +fn (s string) reverse() string { + mut res := string { + len: s.len + str: malloc(s.len + 1) + } + + for i := s.len - 1; i >= 0; i-- { + res[s.len-i-1] = s[i] + } + + return res +} + // 'hello'.limit(2) => 'he' // 'hi'.limit(10) => 'hi' fn (s string) limit(max int) string {