-
Notifications
You must be signed in to change notification settings - Fork 51
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
add findLast string method #723
Conversation
Signed-off-by: Brian Downs <[email protected]>
Signed-off-by: Brian Downs <[email protected]>
Thanks for this! Would it be possible to maybe change the name to |
Signed-off-by: Brian Downs <[email protected]>
Thanks for the review. Changes made. I can do the optional skip in another PR. |
Signed-off-by: Brian Downs <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of small comments!
docs/docs/strings.md
Outdated
@@ -199,6 +199,15 @@ Returns true if a string contains another string. | |||
|
|||
To find the index of a given substring, use the `.find()` method. This method takes an optional second parameter which can be used to skip the first `n` number of appearances of the substring. This method returns `-1` if the substring could not be found. Otherwise, it returns the index of the string. | |||
|
|||
```cs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there's a little bit of a mix up with the docs here, the find examples have went under .findLast
and the findLast
have went under .find
docs/docs/strings.md
Outdated
"woolly woolly mammoth".lastIndexOf("woolly"); // 7 | ||
"mammoth".lastIndexOf("woolly"); // -1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"woolly woolly mammoth".lastIndexOf("woolly"); // 7 | |
"mammoth".lastIndexOf("woolly"); // -1 | |
"woolly woolly mammoth".findLast("woolly"); // 7 | |
"mammoth".findLast("woolly"); // -1 |
tests/strings/findLast.du
Outdated
@@ -0,0 +1,17 @@ | |||
/** | |||
* lastIndexOf.du |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* lastIndexOf.du | |
* findLast.du |
tests/strings/findLast.du
Outdated
/** | ||
* lastIndexOf.du | ||
* | ||
* Testing the str.lastIndexOf() method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Testing the str.lastIndexOf() method | |
* Testing the str.findLast() method |
tests/strings/findLast.du
Outdated
* | ||
* Testing the str.lastIndexOf() method | ||
* | ||
* .lastIndexOf() returns the last index of the given string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* .lastIndexOf() returns the last index of the given string | |
* .findLast() returns the last index of the given string |
Signed-off-by: Brian Downs <[email protected]>
Signed-off-by: Brian Downs <[email protected]>
Thanks for this! |
Thanks for that commit. Apparently my editor's find and replace isn't quite working as expected. I needed this method for a text wrap module I wrote over the weekend. It's super small in Dictu but a pain to do it in C. Do we want to entertain string methods in Dictu like we have with lists and dicts? |
No worries! Yeah built in methods on strings are more than welcome additions |
Awesome. Thanks! |
What's Changed:
Add lastIndexOf string method to find the last index of a given string in another string.
Type of Change:
Housekeeping:
Screenshots (If Applicable):