public class StringSplit { public static List<String> split(String s, int len) { List<String> res = new ArrayList<String>(); int ix = 0; while(ix < s.length()) { int newix = Math.min(ix + len, s.length()); res.add(s.substring(ix, newix)); ix = newix; } return res; } public static void main(String[] args) { String s = "Der var engang en mand der hed Kurt"; List<String> lst = split(s, 4); for(String p : lst) { System.out.println("|" + p + "|"); } } }
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.