Edison Grauman Edison Grauman - 6 months ago 11
Java Question

Shorten a string to whatever is in-between colons

I have to shorten a string to what is in-between two colons. For example if the string said


hello:I am in-between:goodbye


it would result in


I am in-between

Answer

If you can assume that there are exactly two colons (:), you could just split by it:

String input = "hello:I am in-between:goodbye";
String result = input.split(":")[1];