Question : Cut a string in pieces of a given length

Hi,

I have a very long string which I want to cut in pieces of 100 characters.
Of course, the last piece may contain less than 100 characters.

Thank you

Answer : Cut a string in pieces of a given length

For String 's', you could do
1:
2:
3:
4:
5:
6:
7:
8:
	StringReader in = new StringReader(s);
	char[] buf = new char[100];
	int read = -1;
	while((read = in.read(buf)) > -1) {
	    String piece = new String(buf, 0, read);
	    System.out.println(piece);
	}
	in.close();
Random Solutions  
 
programming4us programming4us