+ 4
Find the position of the substring in a string.
If there are more than one substrings available then return the position for the last one. Here position means character position of the first character of substring. Input Format: First line contains a string. Second line contains substring. I/P Hello world Hello reader. Hello O/P 13
2 Answers
+ 6
Here is in Java:
System.out.println(string.lastIndexOf(substring));
+ 1
You can use the str.find(substr) method to find the position of the first one, and then remove that substring to find the next one until there are no other substrings. In each iteration you have to save the number of characters you concatenate or you'll get wrong results!