substring() method worked good for strings with even length. But for Strings with odd length, subString() did not work as desired. Suppose this Strings:
String myString = "Hell";
String anotherString = "Hello";
I want to divide myString into two parts: "He" and "ll" which worked well with substring() as:
part1 = myString.substring(0, input.length()/2);
part2 = myString.substring(input.length()/2, input.length());
But for anotherString, I want "Hel" and "lo", meaning for even length Strings, I want to roundup the beginIndex to next Index. I tried as below but did not always get the same result.
part1 = anotherString.substring(0, input.length()/2+1);
part2 = anotherString.substring(input.length()/2+1, input.length());
I would like to know if there is any better way to split the Strings as I mentioned using regular expression?