?
Solved

search- space character

Posted on 2010-01-12
5
Medium Priority
?
221 Views
Last Modified: 2012-06-27
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
Comment
Question by:coPilot
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 3

Expert Comment

by:burtonrhodes
ID: 26299969
To clarify.... If space is entered, do you want everything returned or do you want just fields that have a "space" in them?
0
 
LVL 40

Expert Comment

by:Gurvinder Pal Singh
ID: 26300427
Is this 'String.trim()' done at the java or Javascript end?

Could you please post the code snippet?
0
 
LVL 2

Accepted Solution

by:
malaki12003 earned 1000 total points
ID: 26300511
// 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
 
LVL 40

Assisted Solution

by:Gurvinder Pal Singh
Gurvinder Pal Singh earned 1000 total points
ID: 26300543
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
 
LVL 5

Expert Comment

by:deeppra
ID: 26301400
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question