(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

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -