(JAVA) Checking whether input string contains a certain word (definite) and removing it -
this question has answer here:
let's have input string of 6 characters followed word "hello"
abcdefhello
or set of data
quernwegngweghello
i mean, word "hello" @ end. how can remove word if possible?
the string dynamic in number, meaning change accordingly check whether word contains "hello" in last 5 characters , remove them if possible.
private static string striphellofromend(string input) { if (input.endswith("hello")) { return input.substring(0, input.length() - "hello".length()); } return input; }
Comments
Post a Comment