• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 223
  • Last Modified:

search- space character

Java application. After I put a cursor in a search field (String) and click on space bar,  I got an error: my WHERE clause with LIKE stops working. ( I use a delimiter(" ") in this search.)
 How should it work if only a space character is entered?  We need to trim it out and treat it as nothing entered at all.   However, String.trim() doesn't work here.
0
coPilot
Asked:
coPilot
2 Solutions
 
burtonrhodesCommented:
To clarify.... If space is entered, do you want everything returned or do you want just fields that have a "space" in them?
0
 
Gurvinder Pal SinghCommented:
Is this 'String.trim()' done at the java or Javascript end?

Could you please post the code snippet?
0
 
malaki12003Commented:
// s for string and c for search character
      int i = 0;
      s.s.trim();
      int index = 0; //number of occurences
      for(i = 0; i < s.length(); i++)
      {
      if (s.charAt(i) != c)
      result++;
      }
      }
      return s.subString(0,index);

Open in new window

0
 
Gurvinder Pal SinghCommented:
When you trim the string, you can check the length of the string to see if it is more than 1.

like
String str = " ";
if ( str.trim().length > 1 )
{
   //string has other characters
}

Methods like substring creates another string objects, so can be avoided here

if you want to trim other chars also, please check this
http://www.javafundu.com/2009/02/trim-prefix-and-suffix-any-characters.html
0
 
deeppraCommented:
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now