I need to get a certain string value after a slash "/" but I am having trouble because the format value of the string is not always the same.
The value of string are the ff:
String raw = "Announcements/announcement_id)";
All I need here is the announcement_id which can be obtain with the use of lastIndexOf("/")+1
but this is not always the format of the string it could be also like this.
String raw = "Announcements/announcement_id/Comments/comment_id)";
Here all I need are both announcement_id and comment_id.
For the last part string value could be also like this.
String raw = "Announcements/announcement_id/Comments/comment_id/Replies/reply_id)";
Here all I need are both comment_id and reply_id.
How do I get this right like using if else statement.
if(has only one slash)
use lastIndexOf("/")+1 to get the id
else if (has three or more slashes)
get the value after second to the last forward slash and last forward slash
announcement_id
in last example? I think a regex would work then