-
Notifications
You must be signed in to change notification settings - Fork 1
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
Negative indexing #6
Comments
Thanks for the suggestion! Unfortunately, this would require changing the On that same note, changing the indices from However, this could instead be resolved by introducing a new, separate method that simply indexes from the back. Something with a signature like pub trait Substring {
fn substring(&self, start_index: usize, end_index: usize) -> &str;
fn substring_from_end(&self, start_index: usize, end_index: usize) -> &str {
self.substring(self.len() - end_index, self.len() - start_index)
}
} I have a few issues with it:
So I guess that's a really long way to say that I am going to punt on this one. I don't think there is enough potential benefit to warrant the changes. |
Support for negative indexing would be helpful.
Example:
string.substring(-5, -3)
On the string "hello world" this would return "wo".
The text was updated successfully, but these errors were encountered: