• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
sarita chaudhary
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.
 
Mahender Parkipandla
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?
 
Paul Clapham
Sheriff
Posts: 22835
43
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?
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate 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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!