Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[String] No way to access nth character of string #1148

Open
danielFHcode opened this issue Oct 3, 2024 · 2 comments
Open

[String] No way to access nth character of string #1148

danielFHcode opened this issue Oct 3, 2024 · 2 comments

Comments

@danielFHcode
Copy link

danielFHcode commented Oct 3, 2024

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 -> Maybe Char
get 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?

Copy link

github-actions bot commented Oct 3, 2024

Thanks for reporting this! To set expectations:

  • Issues are reviewed in batches, so it can take some time to get a response.
  • Ask questions a community forum. You will get an answer quicker that way!
  • If you experience something similar, open a new issue. We like duplicates.

Finally, please be patient with the core team. They are trying their best with limited resources.

@LupusMichaelis
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants