Hi,

I may get more than 1000 lines in a file. Each line ends with a new line character. Sometimes the file may have 4 lines.
Other lines will have characters such as , : alone.

I'm storing each line in the database if it is a valid line and If the line contains only the above characters (, : ) i need to skip the line and doesn't want to save.

Example Input,

Allows you to work and play in a secure computing environment.
,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
Allows you to play online
:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Lines Saved:
Allows you to work and play in a secure computing environment.
Allows you to play online

Currently what i'm skipping the line if it has the above characters as below

Pattern.compile([,:+ ])
Matcher matcher = pattern.matcher(string);
String tmp = matcher.replaceAll("")
if(tmp.length > 0 ) {
/// Skip
}

Is there is any other way to do instead of calling replaceAll ??

I like to know whether is there is any other way to check whether the string contains only those characters and nothing else, so that i can directly skip
instead of calling replaceAll and checking for length?

any pattern or regular expression which should say the line contains only those characters and nothing else, so we can skip the line.

Please help.

Thanks,
Kathir

How about this:

String s = "::::::::::::::::::::::";
        String [] tok = s.split(":");
        System.out.println(tok.length);
        for (int i=0;i<tok.length;i++) {
            System.out.println(">"+tok[i]+"<");
        }

Notice that the length of the 'tok' is zero. But when you do this: String s = "::::::::::::::::::a::::"; The length is not 0.

I think that you can use regular expressions as well with split method. Check the API of the String class

Also I would suggest for you to use the trim method as well:

String s = "    :::::::::::::::::    ";
        s = s.trim();
        String [] tok = s.split(":");
        System.out.println(tok.length);
        for (int i=0;i<tok.length;i++) {
            System.out.println(">"+tok[i]+"<");
        }

When parsing the lines, just to be sure.

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.