How can I encode a URL String?

Question ID : 211
Created on 2013-10-25 at 11:33 AM
Author : Veryant Support [support@veryant.com]

Online URL : http://support.veryant.com/support/phpkb/question.php?ID=211



You can work with the OOP statements using the Java class named "java.net.URLEncoder", available with the Java Runtime, useful to encode a URL string: http://docs.oracle.com/javase/7/docs/api/java/net/URLEncoder.html

The following is an example of a COBOL program that encodes a string using UTF-8 as the encoding scheme:


program-id. pencode.
configuration section.
repository.
 class jencoder as "java.net.URLEncoder"
 class jstring as "java.lang.String"
 class jencodeEx as "java.io.UnsupportedEncodingException"
 .
       
working-storage section.
77 w-jencoder object reference jencoder.
77 w-string object reference jstring.
77 var pic x any length.
       
procedure division.
main.
 try
    set w-string to jstring:>new(""The string ΓΌ@foo-bar")
    set var to jencoder:>encode(w-string, "UTF-8")      
    display var
 catch jencodeEx
    display exception-object
 end-try.   
 stop run.



Back to Original Question