mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
string.reverse() (#641)
This commit is contained in:
parent
8b3802d9b8
commit
a409a60b11
@ -771,6 +771,19 @@ fn (s[]string) join_lines() string {
|
|||||||
return s.join('\n')
|
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'
|
// 'hello'.limit(2) => 'he'
|
||||||
// 'hi'.limit(10) => 'hi'
|
// 'hi'.limit(10) => 'hi'
|
||||||
fn (s string) limit(max int) string {
|
fn (s string) limit(max int) string {
|
||||||
|
Loading…
Reference in New Issue
Block a user