473,396 Members | 1,792 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

word Wrap help, words spilling over word limit!

16
hello my wonderful internet users!

I have been assigned a simple word wrap program. I think I've gotten so wrapped up in the method I'm trying to implement, but it's just not coming together.


the logic:
so I have a variable that counts the length of the line allowed "read in a width"

-I have a variable that counts the length of said list.

-I have something to check to see if the word being messed with is the first in the line or not.


-I check to see if first is true or false
-set the length of the character countering variable

if the CC is less the the width I Want, but not a first word then print a space and the word

-if it is the first word and less then the width then just print the word

and if it exceeds then print a new line and then the word.

but I am getting spill over :(!! its going a little beyond the width each time.

Expand|Select|Wrap|Line Numbers
  1.  
  2. for (String word: words) {
  3.  
  4.         if(cc==0 ||cc ==word.length()){
  5.             first=true;}
  6.             if(cc !=0 && cc !=word.length()){
  7.             first=false; } 
  8.  
  9.  
  10. //if(line.trim().length()==0){out.printf("ANYBONDY HEA ME!!!");}
  11.  
  12.         cc=cc+word.length();
  13.  
  14.         if(cc>width){
  15.         //out.printf("%d",cc);
  16.         out.printf("%n");
  17.          cc=word.length();
  18.             first=true;
  19.                 }
  20.  
  21. //if(cc==0 ||cc ==word.length()){
  22. //            first=true;}
  23.  
  24.         if(first==true){
  25.         out.printf("%s",word);}
  26.  
  27.  
  28.         //if(cc>= width){out.printf("%n");}
  29.         if(cc  <=width&&first==false){
  30.                 out.printf(" ");
  31.                 out.printf ("%s", word);
  32.  
  33.             cc=cc+1;
  34. //out.printf("%d",cc);
  35. }
  36. /*
  37. if(cc==0 ||cc ==word.length()){
  38.             first=true;}
  39.              if(cc !=0 && cc !=word.length()){
  40.             first=false; } 
  41.          if(first==true){cc=cc+word.length();
  42. out.printf("%s",word);}
  43. else{
  44. cc=cc+1;
  45. if(cc+word.length()<width){
  46. out.printf(" ");
  47. out.printf("%s",word);}
  48. else{
  49. out.printf("%n");
  50. cc=0;
  51. out.printf("%s",word);
  52. cc=cc+word.length();
  53. }
  54. }
  55. if(first){out.printf("%d",cc);}
  56. */
  57.  
  58.      }
  59.  
  60.  
Apr 10 '11 #1
1 1774
Dheeraj Joshi
1,123 Expert 1GB
I have trouble understanding what are you trying to achieve.
Can you elaborate the problem bit for me?
Also post whole code here. So that i can get an idea.

Regards
Dheeraj Joshi
Apr 14 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: leegold2 | last post by:
I have been looking for a php word wrap function. I know there's an official PHP function but I've tried that and many of the functions contributed on that php.net page and none do what I...
2
by: Mr TVTL | last post by:
Hi there, I've created a series of layouts designed to be optimized for search engines, and yet also standards-compliant. The problem isn't in the layouts themselves, but in the display of the...
9
by: Joel Byrd | last post by:
I've got a div whose width is specified as a percentage so that if you shrink the browser window, the div shrinks, and the text inside the div wraps around to accommadate this. The problem is:...
10
by: Lorenzo Thurman | last post by:
I have a table cell that I want to wrap text inside of. I've tried both hard and soft wrap, but Firefox refuses to obey. IE 6&7 handle the wrap just fine. Does anyone know how I can fix this?
5
by: momo | last post by:
say i have the following table: <table width="500"> <tr> <td width="250">this is the text im concerned with</td> <td></td> </tr> </table> i need the width of the columns to STAY at 250 and...
1
by: winston.heng | last post by:
Hi, Thanks for reading this posting. I have been cracking my head on solving the infinite loop when i call the following section code. Any help or advise is greatly appreciated =D Thanks in...
1
by: humdum | last post by:
the below code is for word wrap where user can specify no of char per line on text_change event there is problem if anyone can help me to remove this, plz plz if user enter 3-4 lines: "This...
0
by: Seun Oguntomini | last post by:
Hi, How are you and work? Pls am a user of Microsoft Access 2007. There is need for me to enter multiple words in a field in MS Access 2007 which am finding it difficult to do For me to be able...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.