You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, it seems there is no method to get the nth character of a string in the standard library, I'm pretty sure the only way to do so is to first convert it into a list, then into an array, then to use Array.get:
get:Int->String->MaybeCharget index string = string |>String.toList |>List.toArray |>Array.get index
Which takes linier time complexity for something which should be constant. Alternatively you could do String.slice index (index+1) string but that would return a string and not a char.
Is there a reason for the lack of this seemingly basic feature? Or am I missing an existing method, in which case maybe the documentation needs to be updated to make it clearer how to do this?
The text was updated successfully, but these errors were encountered:
Currently, it seems there is no method to get the nth character of a string in the standard library, I'm pretty sure the only way to do so is to first convert it into a list, then into an array, then to use
Array.get
:Which takes linier time complexity for something which should be constant. Alternatively you could do
String.slice index (index+1) string
but that would return a string and not a char.Is there a reason for the lack of this seemingly basic feature? Or am I missing an existing method, in which case maybe the documentation needs to be updated to make it clearer how to do this?
The text was updated successfully, but these errors were encountered: