-
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
Changes from 4 commits
7606e56
e1ae3bc
9564999
7344f18
eb526ed
256ca6f
dd93796
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -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 | ||||||||||
"woolly woolly mammoth".lastIndexOf("woolly"); // 7 | ||||||||||
"mammoth".lastIndexOf("woolly"); // -1 | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
``` | ||||||||||
|
||||||||||
### string.findLast(String) -> Number | ||||||||||
|
||||||||||
Returns the last index of the given string. If the substring doesn't exist, -1 is returned. | ||||||||||
|
||||||||||
```cs | ||||||||||
"Hello, how are you?".find("how"); // 7 | ||||||||||
"hello something hello".find("hello", 2); // 16 (Skipped first occurrence) | ||||||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,17 @@ | ||||||
/** | ||||||
* lastIndexOf.du | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* | ||||||
* Testing the str.lastIndexOf() method | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
* | ||||||
* .lastIndexOf() returns the last index of the given string | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
*/ | ||||||
from UnitTest import UnitTest; | ||||||
|
||||||
class TestStringLastIndexOf < UnitTest { | ||||||
testStringLower() { | ||||||
this.assertEquals("woolly woolly mammoth".findLast("woolly"), 7); | ||||||
this.assertEquals("mammoth".findLast("woolly"), -1); | ||||||
} | ||||||
} | ||||||
|
||||||
TestStringLastIndexOf().run(); |
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 thefindLast
have went under.find