Created
December 14, 2015 05:21
-
-
Save erjan/b676d7b63c8a969932d8 to your computer and use it in GitHub Desktop.
split a long string but not in the middle of a word
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private String[] split_string(String newQuestion){ | |
/* | |
this: | |
"According to Ruzbihan, these 2 tribe | |
s were part of both uzbek and mangits" | |
must be: | |
"According to Ruzbihan, these 2 tribes | |
were part of both uzbek and mangits" | |
*/ | |
String[] words = newQuestion.split(" "); | |
String first_part = ""; | |
String second_part = ""; | |
int size = 0; | |
for(int i = 0; (first_part.length() + words[i].length()) < newQuestion.length()/2 ; i++) { | |
size++; | |
first_part += words[i] + " "; | |
} | |
for(int j = size; j < words.length; j++) { | |
second_part += words[j] + " "; | |
} | |
return new String[]{first_part,second_part}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment