• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

How to break a single long string into multiple lines in java class?

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have created an application using hibernate and struts.In which a form is created where the user will enter all its personal details(for e.g name ,phone no. and address).
Here for address I have used textarea and whenever user enters the address, sometimes it can be a long string also.
So the problem is if a long string is entered then while displaying that ,address comes on single line and the page is stretched
So can anyone tell me how to break this single string into mutiple lines in java class?

Thanks in advance.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
You can split the string based on delimiter. Identify the delimiter from string and with StringBuffer you can split the string.
Please refer methods of StringBuffer for more information on splitting the string.
 
sarita chaudhary
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
There are not fixed delimiters in the string so that I can split the string using that.The string can be anything(any combination) for e.g. there can be a 100 characters in a string with no space at all.
Then how to split that?
 
Marshal
Posts: 25805
69
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So far you have no rules which tell you how to split the string, so this is not a Java question. Your first step should be to find the rules. Is that your responsibility or do you have incomplete requirements?
 
Bartender
Posts: 10777
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

sarita chaudhary wrote:Here for address I have used textarea and whenever user enters the address, sometimes it can be a long string [...] So can anyone tell me how to break this single string into mutiple lines in java class?


Why should you have to?

It seems to me that your basic problem is that you've used a TextArea; not that you have a long string. Why not use something more geared for entering single lines of text, and have more than one of them?

Indeed, addresses are notoriously complex things, involving numbers and street names and postcodes and counties/states (or maybe none of them); so it might actually be worth thinking about an Address class that encompasses all these things, and for now keep it really simple. You can always add the "clever" stuff later - that's the beauty of classes.

Winston
 
    Bookmark Topic Watch Topic
  • New Topic