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?
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.
posted 5 years ago
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?
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?
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.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here