berry icon indicating copy to clipboard operation
berry copied to clipboard

Adding `string.startswith()` and `string.endswith()`

Open s-hadinger opened this issue 1 year ago • 1 comments

@skiars Are you ok to add:

  • string.startswith(hay:string, needle:string [, case_insensitive:bool]) -> bool
  • string.endswith(hay:string, needle:string [, case_insensitive:bool]) -> bool

After writing some decent amount of code, it is quite common to have to check if a string starts or ends with a specific value. The current way to do it are not straightforward:

startswith (case sensitive):

def startswith(hay, needle)
    import string
    return string.find(hay, needle) == 0
end

endswith is not as straightforward to implement, and both lack case-insensitive check which would be useful for file extensions.

s-hadinger avatar Mar 05 '24 16:03 s-hadinger

This is very necessary.

skiars avatar Mar 06 '24 01:03 skiars