Reputation: 121
How to find a .
from back to front in string
String calc = "abcd+abcd.abcd+abcd-abcd.abcd"
for (int i = calc.length(); i > 0; i--) {
if (calc.charAt(i) == '.') {
//Do something
}
}
Upvotes: 2
Views: 68
Reputation: 201437
Almost correct, I believe you want -
// for (int i = calc.length(); i > 0; i--) {
for (int i = calc.length() - 1; i >= 0; i--) { // <-- 0 is the first character.
Upvotes: 3