Shoutbox

Space words out in JAVA? - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Skype & Technology (/forumdisplay.php?fid=9)
+---- Forum: Tech Talk (/forumdisplay.php?fid=17)
+----- Thread: Space words out in JAVA? (/showthread.php?tid=69318)

Space words out in JAVA? by albert on 12-10-2006 at 01:36 AM

hey guys I'm searching for a way to actually justify a text by coding it.

what i did until now is find how many caracters are written.. then i got 80 which is the maximum there should be and did

80 - number of caracthers present
replaced all ponctuation by spaces
trimmed the string so no spaces are before or after text
counted how many spaces
divided numbers of spaces left by the number of spaces there is

now i just want to know how i could add spaces between the words.
I can't seem to find a way..

:S


RE: Space words out in JAVA? by foaly on 12-10-2006 at 04:05 PM

I'm not really understanding what you want...
you have a string off words... between the words are spaces and you want to add spaces?
couldn't you just do something like:

code:
String s="the string";
int i=0;
while(i>-1&&i<s.length){
   i=s.IndexOf(" ",i);
   String temp1 = s.substring(0,i);
   String temp2 = s.substring(i,s.length);
   temp1 +=" ";
   s= temp1+temp2
}

or something like that?
RE: Space words out in JAVA? by RaceProUK on 12-10-2006 at 07:24 PM

quote:
Originally posted by alby
hey guys I'm searching for a way to actually justify a text by coding it.
Where are you writing the text to?