Results 1 to 2 of 2
  1. #1
    Pojahn_M's Avatar
    Pojahn_M is offline Senior Member
    Join Date
    Mar 2011
    Location
    Sweden
    Posts
    197
    Rep Power
    4

    Default Check if a string contains whitespace characters

    I want to make a check that find if a string only contains whitespace characters.

    I added this: "String".matches("\\s")
    This work as long as the strings length is equal to 1. If the string contains two or more spaces(or a tabb space), it will fail.

    Tipps?

    Edit: Never mind. I found a way, by calling string.trim () and then string.isEmpty ().
    Last edited by Pojahn_M; 03-08-2012 at 08:10 PM.

  2. #2
    eRaaaa is offline Senior Member
    Join Date
    Oct 2010
    Location
    Germany
    Posts
    787
    Rep Power
    5

    Default Re: Check if a string contains whitespace characters

    \\s = one whitespace character
    \\s+ = one or more times

Similar Threads

  1. Replies: 4
    Last Post: 11-05-2010, 10:43 AM
  2. check string inside string
    By alacn in forum New To Java
    Replies: 8
    Last Post: 07-07-2010, 12:52 PM
  3. Replies: 1
    Last Post: 04-30-2010, 03:21 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
  •