Title: How can I encode a URL String?

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.
 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.
    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
 stop run.

Authored by: Veryant Support on Fri, Oct 25th, 2013 at 7:00 PM
This question has been viewed 5941 times so far.
Online URL: http://support.veryant.com/support/phpkb/question.php?ID=211

Powered by PHPKB Knowledge Base Software