• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 948
  • Last Modified:

StringTokenizer to break paragraph by new line ( ignoring space )

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
paluindian
Asked:
paluindian
  • 4
  • 3
1 Solution
 
paluindianAuthor Commented:
I can not use File for this. I extract this passage from JTextArea of our application
0
 
paluindianAuthor Commented:
I guess I can make use of Pattern.split right?
I dont know how though
0
 
CEHJCommented:
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
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
CEHJCommented:
>>I guess I can make use of Pattern.split right?

Not in 1.3
0
 
paluindianAuthor Commented:
Ohh looks like Pattern class in available in java 1.4.2 and not java 1.3.1
0
 
paluindianAuthor Commented:
Yep CEHJ it worked!! and this time it really worked programmatically not manually ;-) Last time my mistake ;-)
Thanks so much,
Paluindian
0
 
CEHJCommented:
:-)
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now