|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hello,
I am working on a JSP search script. I have a list of results displayed after a search is run, with each individual result only displaying the first 195 characters of the results body text. Instead of using the following code.... shortBody = ad.getBody().substring(0, 195) .....I want to make the shortBody pick out the first three lines, rather than the first 195 characters. Is that possible? Thanks, Ida |
|
#2
|
||||
|
||||
|
I've no idea how efficient this will be but it does the trick. It basically finds the third occurrance of '\n' and gets a substring from 0 to it. I'm assuming that shortBody and ad are Strings.
Code:
shortBody = ad.getBody().substring(0, ad.indexOf("\n", ad.indexOf("\n", ad.indexOf("\n") + 1) + 1)) ;
~ishnid
__________________
~ishnid; Have you tried: [ search.cpan.org | perldoc | Java API | mysql.com | google ] Apostrophes are NOT used for possessive pronouns or for noun plurals, including acronyms. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > Displaying first 3 lines of a variable |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|