dcsimg
Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.


Tip of the Day
Language: Java
Expertise: Intermediate
Jan 16, 2007

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


Using the URLEncoder/URLDecoder Classes

To include special characters such as spaces and quotes in a URL string, you need to encode them. Similarly, you need to decode encoded characters in a URL to recover the original URL. The following code demonstrates how to code/decode a string using the URLEncoder/URLDecoder classes.

import java.net.*;

public class URL_Encoder_Decoder{

public static void main(String[] args){

  String sir="@sir de caractere@,nr. 1290 'paragraf 3'";
  try{
     String sir_codat=URLEncoder.encode(sir,"UTF-8");
     String sir_decodat=URLDecoder.decode(sir_codat,"UTF-8");
     System.out.println(sir);
     System.out.println(sir_codat);  
     System.out.println(sir_decodat);      
     }catch(java.io.UnsupportedEncodingException e)
         {System.out.println("Eroare:"+e.getMessage());}            
  }
}
Here's the result:

@sir de caractere@,nr. 1290 'paragraf 3'
%40sir+de+caractere%40%2Cnr.+1290+%27paragraf+3%27
@sir de caractere@,nr. 1290 'paragraf 3'
Leonard Anghel
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date