I want split a string for example: 5121321 in 5 121 321, every 3 is a ' '. I have that code:
private void compor()
{
String dinheiro="5121321";
char aux[]= new char[dinheiro.length()];
for(int i=0;i<dinheiro.length();i++)
{
aux[i]=dinheiro.charAt(i);
}
int flag=0;
String total="";
for(int i=0;i<dinheiro.length();i++)
{
if(flag==3)
{
total+=' ';
flag=0;
}
total += String.valueOf(aux[i]);
flag++;
}
TextView txt = (TextView) findViewById(R.id.textView3);
txt.setText(String.valueOf(total));
}
The problem is the output of this is: 512 132 1 and i want 5 121 321. Sorry my english. Somebody can help me?Thanks.