Similar to a question posted here, am looking for a solution in Java.
That is, how to find the index of nth occurrence of a character/string from a string?
Example: "/folder1/folder2/folder3/". In this case, if I ask for 3rd occurrence of slash (/), it appears before folder3, and I expect to return this index position. My actual intention is to substring it from nth occurrence of a character.
Is there any convenient/ready-to-use method available in Java API or do we need to write a small logic on our own to solve this?
Also,
- I quickly searched whether any method is supported for this purpose at Apache Commons Lang's StringUtils, but I don't find any.
- Can regular expressions help in this regard?