String methods: .slice(), .capitalize()
frsechet opened this issue · comments
Francois Falala-Sechet commented
Is your feature request related to a problem? Please describe.
It's quite hard to manipulate strings as they are currently not iterable.
Describe the solution you'd like
.slice(start, count) similar to the JS version of str.slice(): https://developer.mozilla.org/fr/docs/Web/JavaScript/Reference/Objets_globaux/String/slice
(careful for multibyte strings, unicode etc.)
.capitalize(): change the first letter to uppercase
Describe alternatives you've considered
It's recodable with native CSML code but it's quite cumbersome! For example:
fn capitalize(str):
do acc = []
do first = false
foreach (letter) in str.split("") {
if (!letter.length()) continue
if (!first) do acc.push(letter.to_uppercase())
else do acc.push(letter)
do first = true
}
return acc.join("")