mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: string interpolation field width support for large integers and utf8 strings
This commit is contained in:
@ -215,6 +215,14 @@ Both single and double quotes can be used to denote strings. For consistency,
|
||||
Interpolation syntax is pretty simple. It also works with fields:
|
||||
`'age = $user.age'`. If you need more complex expressions, use `${}`: `'can register = ${user.age > 13}'`.
|
||||
|
||||
Format specifiers similar to those in C's `printf()` are supported, too. `f`, `g`, `x`, etc. are optional
|
||||
and specify the output format. The compiler takes care of the storage size, so there is no `hd` or `llu`.
|
||||
|
||||
```v
|
||||
println('x = ${x:12.3f}'`
|
||||
println('${item:-20} ${n:20d})
|
||||
```
|
||||
|
||||
All operators in V must have values of the same type on both sides. This code will not compile if `age` is an `int`:
|
||||
|
||||
```v
|
||||
|
Reference in New Issue
Block a user