LingDong- / wax

A tiny programming language that transpiles to C, C++, Java, TypeScript, Python, C#, Swift, Lua and WebAssembly 🚀
https://waxc.netlify.app/
MIT License
783 stars 45 forks source link

What string operations are supported? #13

Closed johnynek closed 3 years ago

johnynek commented 3 years ago

The quickstart only mentions appending to strings and comparing strings. It does not mention accessing the length of strings or indexing characters or substrings. Is that supported?

LingDong- commented 3 years ago

Hi @johnynek,

Thanks for pointing out the missing documentation. Yes these are supported. Just added to quickstart: 2a22036397c992003742c91f963e6f491a831b3f

To find out the length of a string:

(# s)

To get a character from a string:

(let s str "hello")
(let c int (get s 0)) ;; 'h'==104

To copy part of a string into a new string use (slice s i n) the same way as slice for arr:

(let s str "hello")
(slice s 1 3)  ;; "ell"