Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

StringTokenizer to break paragraph by new line ( ignoring space )

Posted on 2004-08-31
7
Medium Priority
?
943 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 200 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 
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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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.
The viewer will learn how to implement Singleton Design Pattern in Java.
This video teaches viewers about errors in exception handling.
Suggested Courses

704 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