Solved

How can I trim this?

Posted on 2006-07-17
4
226 Views
Last Modified: 2010-03-31
How can I trim this string?  
It has a space at the end.

<%
String username1 = (String)session.getAttribute("j_username");
%>
0
Comment
Question by:g118481
  • 2
4 Comments
 
LVL 23

Assisted Solution

by:Ajay-Singh
Ajay-Singh earned 50 total points
ID: 17124573
using trim() function should help:


String username1 = (String)session.getAttribute("j_username");
username1 = username1.trim();
0
 
LVL 86

Accepted Solution

by:
CEHJ earned 75 total points
ID: 17124649
You need to check for null

String username1 = (String)session.getAttribute("j_username");
if (username1 != null) {
    username1 = username1.trim();
}
      
      
0
 
LVL 1

Author Comment

by:g118481
ID: 17124735
Thank you.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17124745
:-)
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now