Created
July 21, 2014 18:58
-
-
Save ferronrsmith/22c15e743acea1c08272 to your computer and use it in GitHub Desktop.
Delimited Split
This file contains 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 pInputString, String pDelim, int pMaxLength) { | |
int len = pInputString.length(); | |
int times = len / pMaxLength; | |
boolean remainder = len % pMaxLength != 0; | |
int startIdx = 0; | |
int endIdx = pMaxLength; | |
StringBuilder res = new StringBuilder(); | |
if (len <= pMaxLength) { | |
return pInputString; | |
} else { | |
for (int i = 0; i < times; i++) { | |
res.append(pInputString.substring(startIdx, endIdx)); | |
res.append(pDelim); | |
// increment | |
endIdx += pMaxLength; | |
startIdx += pMaxLength; | |
} | |
if (remainder) { | |
res.append(pInputString.substring(startIdx)); | |
} | |
} | |
return res.toString(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment