Solved

StringTokenizer to break paragraph by new line ( ignoring space )

Posted on 2004-08-31
7
930 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
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…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

911 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

Need Help in Real-Time?

Connect with top rated Experts

25 Experts available now in Live!

Get 1:1 Help Now