I have a string, and I want to extract the text abcd from this string. I useed the indexOf() method to get the start index, but how we can I set the end index value? The abcd text value is dynamic, so we can't hardcode it like startIndex()+5. I need some logical code.
String str = "Hi Welcome to stackoverflow : " +"\n"+"Information :"+"\n"+"hostname : abcd"+"\n"+
"questiontype : text"+"value : desc.";
if(str.contains("hostname : "))
{
String value = "hostname : "
int startIndex = str.indexof("hostname : ") + value.length();
// how to find the endIndex() in that case
}
String::substring,String::indexOf,String::length.str.substring(startIndex, str.indexOf("\n", startIndex)).