hi, could sm1 please show me code that can sort and read text/string character by character into an array i.e identify integers and characters and put them in separate fields in an array e.g 2 integers then 3 characters like 23 IAM, 12 Her, or 32 MALE. it shuld also reject strings that dont fall into that order e.g 2F 32FL, Male22 or IF23

I don't know that sm1 is around today. Are you sure he/she is on this forum?

Hi Chris,

you might want to take the time to properly format your question. It sounds like a homework assignment, so try to break it down into steps first.

For example:

You say that you have to place data into an array, integers or Strings. Are you going to be using a single array, or will you be using two arrays, one for the integers and one for the Strings. This is important, as a normal array can only store one type at a time, so either String or integer. If you really need to use a single array, then you have to create an object that you will be placing in the array. This object will then contain both an integer and a String.

My policy on homework questions is that if I do not see someone showing actual code where they have really tried to solve the problem, I won't answer. I think it's probably the same for most folks on this forum, so show us that you have put in the effort and someone will surely help you.

Regards
Ewald

ok. the segment of code that does the printing of the file looks like this:

    if (parsefilename.isEmpty())
        JOptionPane.showMessageDialog(null,"Please enter name to save file","Missing filename", JOptionPane.INFORMATION_MESSAGE);
    else{
        try{

        //txtparse1.setText(textOut);

        out2 = new FileOutputStream(txtparsefile.getText().concat("_parsefile.txt"));//save as text file
        p2 = new PrintStream(out2);

        textOut2 = textOut;
        txtparse1.setText(textOut2);

        p2.print(textOut);
        }
        catch(Exception e){
            JOptionPane.showMessageDialog(null, "Error writing to file", "File write error", JOptionPane.INFORMATION_MESSAGE);
        }

and the output looks like this;

Hello worldest
Hello world
Hello world
Hello world
Hello world
Hello world
" Hello world!! "
Oya!
Yes!
important Yellow
21 M 23415 GOOD
20 F 51433 BAD
23 F 31532 TRUE
20 M 54143 BAD

1) i want to select the last 4 lines of output like "21 M 23145 GOOD" and reject the other text like "Hello world"

2) i want to store the selected text into a 4 dimensional array that stores each part of the text separately e.g [20] [M] [54143] [BAD]

somebody help, please

want to select the last 4 lines of output

What is the criteria for selecting one line vs another?
Starts with a number? Has 4 words/parts? ???

tore the selected text into a 4 dimensional array

Thats a lot of dimensions? Your example with strings for indexes doesn't make sense.
Could you describe what you mean better?
A 4 dimensional array would be: String[][][][] fourDims
then you assign it values: fourDims[idx1][idx2][idx3][idx4] = "20";
Would a two dim array work? The first dim would be the line number.
The second dim would be the words in the line:
twoDim[lineNbr][0] = "20"
twoDim[lineNbr][1] = "M'
twoDim[lineNbr][2] = "54143];
etc

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.