flofriday / Moose

🐐 A new fun programming language
MIT License
6 stars 1 forks source link

Implement indexing for Strings #23

Closed flofriday closed 1 year ago

flofriday commented 1 year ago

Example

func removeLeadingDots(text: String) > String {
    mut cnt = 0
    for c in text {
        if c != "." {
            break
        }
        cnt +: 1
    }

    out = ""
    for mut i = cnt; i < text.length(); i +: 1 {
      out +: text[i]
    }

    return out
}

print(removeLeadingDots("......Flotschi!"))

Notes

This is wired because we don't have a Char datastructure so indexing into a string returns a new string with a single character inside it.