Solved

StringTokenizer to break paragraph by new line ( ignoring space )

Posted on 2004-08-31
7
935 Views
Last Modified: 2008-02-01
Hello Everybody,

I want to break the paragraph into lines and want to store it in an array.
I can not use APLIT function...somehow its not available. I'm using Java 1.3.1
I know stringtikenizer can do it but it break the lines by default on "SPACE" also. I want to eliminate that.

Following the type of paragraph I want to break into lines.

-- -----------------------------------------------
-- Query from table AUTOMATION.EMPLOYEE
-- Tue Aug 31 11:18:36 PDT 2004
-- -----------------------------------------------
SELECT
     A.EMPNO, A.FIRSTNME, A.MIDINIT,
     A.LASTNAME, A.WORKDEPT, A.PHONENO,
     A.HIREDATE, A.JOB, A.EDLEVEL,
     A.SEX, A.BIRTHDATE, A.SALARY,
     A.BONUS, A.COMM
FROM
     AUTOMATION.EMPLOYEE A
 


Thanks,
Paluindian
0
Comment
Question by:paluindian
  • 4
  • 3
7 Comments
 

Author Comment

by:paluindian
ID: 11945248
I can not use File for this. I extract this passage from JTextArea of our application
0
 

Author Comment

by:paluindian
ID: 11945289
I guess I can make use of Pattern.split right?
I dont know how though
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 50 total points
ID: 11945370
This will retun an array of String, given a String input:

      static String[] breakStringOnNewline(String s) {
            ArrayList result = null;
            try {
                  result = new ArrayList();
                  BufferedReader in = new BufferedReader(new StringReader(s));
                  String line = null;
                  while ((line = in.readLine()) != null) {
                        result.add(line.trim());
                  }
            }
            catch (IOException e) {
                  e.printStackTrace();
                  return null;
            }
            return (String[])result.toArray(new String[result.size()]);
      }
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Expert Comment

by:CEHJ
ID: 11945375
>>I guess I can make use of Pattern.split right?

Not in 1.3
0
 

Author Comment

by:paluindian
ID: 11945376
Ohh looks like Pattern class in available in java 1.4.2 and not java 1.3.1
0
 

Author Comment

by:paluindian
ID: 11945630
Yep CEHJ it worked!! and this time it really worked programmatically not manually ;-) Last time my mistake ;-)
Thanks so much,
Paluindian
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 11945677
:-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet filter example 37 82
Error in @AspectJ Based AOP with Spring 2 23
java imports not found 4 47
passing enum to a method 4 34
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question