Jump to content

Anyone can help me ?

- - - - -

  • Please log in to reply
9 replies to this topic

#1
xxxxjayxxx

xxxxjayxxx

    Programmer

  • Members
  • PipPipPipPip
  • 123 posts
When I read up the contents in a text file ... How can I remove certain char that I dont want it to be display when I print out the contents from the text file ?

e.g. the content in the file is
Name : XXXXXX
Age : 19

I want to remove the "Name :" and "Age :" , so that XXXXXX and 19 will be display ..

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Like so:

        String line1 = "Name : XXXXXX";

        String line2 = "Age : 19";


        line1 = line1.replaceAll("^Name : ", "");

        line2 = line2.replaceAll("^Age : ", "");

        System.out.println(line1);

        System.out.println(line2);

Or:

String line3 = "Birthdate : 19/09/1999";

line3 = line3.substring(line3.indexOf(":")+2);



#3
xxxxjayxxx

xxxxjayxxx

    Programmer

  • Members
  • PipPipPipPip
  • 123 posts
what if there's many file name in the text content... How can I remove all the file name fromthe content?

#4
xxxxjayxxx

xxxxjayxxx

    Programmer

  • Members
  • PipPipPipPip
  • 123 posts
Anyone can help ?

#5
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
You do it line by line, using wim DC's suggestion.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#6
xxxxjayxxx

xxxxjayxxx

    Programmer

  • Members
  • PipPipPipPip
  • 123 posts

WingedPanther said:

You do it line by line, using wim DC's suggestion.

There's thouands of filename ... and you want me to do it line by line ? ... It will take hours for me to do that ... LOL ?

#7
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
A loop, home slice.
ArrayList<String> strs = new ArrayList<String>();

for (String extractValueFrom : userInputLines)

{

    strs.add(extractValueFrom.substring(extractValueFrom.indexOf(":") + 2));

}
Now the extracted values are in the ArrayList strs. You can display those using an equivalent loop with System.out.println(strs.get(i)).
Wow I changed my sig!

#8
xxxxjayxxx

xxxxjayxxx

    Programmer

  • Members
  • PipPipPipPip
  • 123 posts

ZekeDragon said:

A loop, home slice.
ArrayList<String> strs = new ArrayList<String>();

for (String extractValueFrom : userInputLines)

{

    strs.add(extractValueFrom.substring(extractValueFrom.indexOf(":") + 2));

}
Now the extracted values are in the ArrayList strs. You can display those using an equivalent loop with System.out.println(strs.get(i)).

sorry I dont get what you are tryong to say ...
here's my code :
FileInputStream file = null;

        try {

            file = new FileInputStream("C:\\Users\\Johnny\\Downloads\\Desktop\\TheFile.csv");

            BufferedReader br = new BufferedReader(new InputStreamReader(file));

            String strLine = null;


            while ((strLine = br.readLine()) != null) {

                String results = strLine.replaceAll(".mol2", "").replace(",", "");

                      

                if (strLine.trim().contains("Name")) {

                    continue;

                }

               

                System.out.println(results);

            }

        } catch (IOException e) {

            e.printStackTrace(); // Alternate way to print the entire error


        } finally {

            // Close file

            try {

                if (file != null) {

                    file.close();

                }

            } catch (IOException e) {

                e.printStackTrace();

            }


        }

    }
all files names all contain a .mol2 extension .. How can I modify it with your code ?
Sorry I anot very good in java :(

#9
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Just add

results = results.substring(results.indexOf(":") + 2)

in the while loop I guess.

#10
xxxxjayxxx

xxxxjayxxx

    Programmer

  • Members
  • PipPipPipPip
  • 123 posts

wim DC said:

Just add

results = results.substring(results.indexOf(":") + 2)

in the while loop I guess.

this is the exactly ans i'm looking for ... thx ;)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users