Results 1 to 2 of 2
  1. #1
    j_kathiresan is offline Member
    Join Date
    Feb 2008
    Posts
    12
    Rep Power
    0

    Default How to check whether the string contains only the specified characters ????

    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

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    765
    Rep Power
    6

Similar Threads

  1. characters from a string into an integer
    By 2potatocakes in forum New To Java
    Replies: 7
    Last Post: 05-08-2012, 12:31 PM
  2. Swap characters in a string.
    By Sdannenberg3 in forum New To Java
    Replies: 4
    Last Post: 03-04-2010, 08:49 PM
  3. deleting characters from a String
    By Hayzam in forum New To Java
    Replies: 4
    Last Post: 08-29-2008, 12:14 PM
  4. how to get the characters one by one from a String?
    By Somitesh Chakraborty in forum New To Java
    Replies: 3
    Last Post: 08-20-2008, 08:56 PM
  5. Getting all characters in a String
    By Alayna in forum New To Java
    Replies: 2
    Last Post: 05-20-2007, 11:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •