lbovet / yglu

Yglu ᕄ !? - YAML glue for structural templating and processing
https://yglu.io
MIT License
89 stars 6 forks source link

How to use slice for string varible #14

Closed Alexzsh closed 2 years ago

Alexzsh commented 2 years ago

How to use slice for string varible like -- input a: "12312" b: !? $_.a[:2] -- output a: "12312" b: "12"

lbovet commented 2 years ago

Yglu uses YAQL as expression language. So you can achive the wanted result with substring and len https://yaql.readthedocs.io/en/latest/standard_library.html#substring

lbovet commented 2 years ago

Actually you can also use negative index with substring

# input
a: "12345"
b: !? $_.a.substring(-2,2)
# output
a: '12345'
b: '45'