This language bar is your friend. Select your favorite languages!
Select your favorite languages :
- Or search :
int i = s.lastIndexOf(w),
m = s.length(), n = w.length();
t = i == m - n ? s.substring(0, i) : s;
String t = s;
int index = s.lastIndexOf(w);
if (index + w.length() == s.length()) {
t = s.substring(0, index);
}
Java does not have a native String method for this.
s.lastIndexOf(w) gives the index where w can be found in s starting at the end of s and moving towards the beginning, or -1 if it isn’t there.
s.lastIndexOf(w) gives the index where w can be found in s starting at the end of s and moving towards the beginning, or -1 if it isn’t there.
local t = s:gsub(w.."$", "")
The $ attached to w matches the end of the string s and is replaced by an empty string.
programming-idioms.org