Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trimming spaces out of a String returned from DB2 query

Status
Not open for further replies.

Sch3lp

Programmer
Aug 13, 2002
3
BE
Hi, I've got a sort of a challenge...

A DB2 query that returns a CHAR type (not VARCHAR) is being set to a String. When this string is printed it has spaces behind it, because when you insert into a char-column in DB2 it fills the rest with spaces. Now we want to trim these spaces out of the String, but the trim method doesn't seem to work.
Any alternatives or better solutions are _very_ welcome.

TIA

Tim Schraepen.
 
If you are trying to remove white space...try this...hope this helps.

Code:
public String removeWhiteSpaces (String inString) 
{   
     StringBuffer newString = new StringBuffer();   
     for (int count = 0; count < inString.length(); count++)
     {
	     if (! Character.isWhitespace(inString.charAt(count))) 
	     {         
		     newString.append(inString.charAt(count));
	     }
     }
     return newString.toString();
}
 
Thanks for responding so quickly.
But it seems the error wasn't due to fact that java didn't trim the string correctly. It was a whole other issue.
But I'll try it anyway.
The reason why the trim method doesn't trim the white spaces coming from a DB2 query is because the character returned is lower than some value java uses to verify if it's dealing with a white space or not. Something like that.

But as I said before, thanks for the quick response, you've been very helpful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top