mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
builtin: add method byte()
for string (#11998)
This commit is contained in:
parent
c151e075e1
commit
a17b943e87
@ -459,6 +459,11 @@ pub fn (s string) f64() f64 {
|
||||
return strconv.atof64(s)
|
||||
}
|
||||
|
||||
// u8 returns the value of the string as u8 `'1'.u8() == u8(1)`.
|
||||
pub fn (s string) byte() u8 {
|
||||
return byte(strconv.common_parse_uint(s, 0, 8, false, false) or { 0 })
|
||||
}
|
||||
|
||||
// u16 returns the value of the string as u16 `'1'.u16() == u16(1)`.
|
||||
pub fn (s string) u16() u16 {
|
||||
return u16(strconv.common_parse_uint(s, 0, 16, false, false) or { 0 })
|
||||
|
@ -418,6 +418,7 @@ fn test_arr_contains() {
|
||||
fn test_to_num() {
|
||||
s := '7'
|
||||
assert s.int() == 7
|
||||
assert s.byte() == 7
|
||||
assert s.u64() == 7
|
||||
f := '71.5 hasdf'
|
||||
// QTODO
|
||||
|
Loading…
Reference in New Issue
Block a user