Solved

StringTokenizer to break paragraph by new line ( ignoring space )

Posted on 2004-08-31
7
929 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
Comment Utility
I can not use File for this. I extract this passage from JTextArea of our application
0
 

Author Comment

by:paluindian
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 86

Expert Comment

by:CEHJ
Comment Utility
>>I guess I can make use of Pattern.split right?

Not in 1.3
0
 

Author Comment

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

Author Comment

by:paluindian
Comment Utility
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
Comment Utility
:-)
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
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 how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

772 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

11 Experts available now in Live!

Get 1:1 Help Now