java - removing white spaces from string value -


i have link http://localhost:8080/reporting/pvsusageaction.do?form_action=inline_audit_view&days=7&projectstatus=scheduled&justificationid=5&justificationname= no technicians in area in struts based web application.

the variable in url justificationname have spaces before vales shown. when value of justificationname using request.getparameter("justificationname") gives me value spaces given in url. want remove spaces. tried trim() tries str = str.replace(" ", ""); of them did not removed spaces. can 1 tell other way remove space.

noted 1 more thing did right click on link , opened link new tab there noticed link looks like.

http://localhost:8080/reporting/pvsusageaction.do?form_action=inline_audit_view&days=7&projectstatus=scheduled&justificationid=5&justificationname=%a0%a0%a0%a0%a0%a0%a0%a0no%20technicians%20in%20area 

notable point in address bar shows %a0 white spaces , show %20 space see link , tell difference please if 1 have idea it.

edit here code

string justificationcode = "";         if (request.getparameter("justificationname") != null) {                         justificationcode = request.getparameter("justificationname");         }         justificationcode = justificationcode.replace(" ", ""); 

note: replace function remove space inside string not removing starting spaces. e-g if string " string" after using replace becomes " thisisstring"

thanks in advance

manual trim

you need remove spaces string. remove number of consecutive spaces.

string trimmed = str.replaceall(" +", ""); 

if want replace whitespace characters:

string trimmed = str.replaceall("\\s+", ""); 

url encoding

you use urlencoder, sounds more appropriate way go:

import java.net.urlencoder; string url = "http://localhost:8080/reporting/" + urlencoder.encode("pvsusageaction.do?form_action=inline_audit_view&days=7&projectstatus=scheduled&justificationid=5&justificationname= no technicians in area", "iso-8859-1"); 

Comments

Popular posts from this blog

user interface - Python attempting to create a simple gui, getting "AttributeError: 'MainMenu' object has no attribute 'intro_screen'" -

jquery - Common JavaScript snippet to share files on Google Drive, Dropbox, Box.net or SkyDrive -

Android Gson.fromJson error -