Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert a string to an array in vlang

Tags:

vlang

I'm learning V, and as far as my attempts go, although a V string is an array of bytes, array methods are not applicable to strings. So I want to convert a string to an array. I have tried searching for this with no success, I found something in Go, but it's not usable in V:

[]byte("Here is a string....")

Is there any way to convert a string to an array in V?

like image 804
Phu Nguyen Avatar asked Nov 01 '25 22:11

Phu Nguyen


1 Answers

You can use string.split(delim string) to just array and string.bytes() for an array of bytes:

Welcome to the V REPL (for help with V itself, type `exit`, then run `v help`).
V 0.2.2 8650ec6
Use Ctrl-C or `exit` to exit, or `help` to see other available commands
>>> x := "test"
>>> x.split("")
['t', 'e', 's', 't']
>>> x.bytes()
[t, e, s, t]
like image 195
Peter Badida Avatar answered Nov 04 '25 03:11

Peter Badida



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!