GenoPro Developer Home
GenoPro Home  |  SDK Home  |  Report Generator  |  Support  |  Search  |  Help  |  Site Map

Skip Navigation Links.

Util.HrefEncode Method

The HrefEncode method is similar to UrlEncode, however it is designed to encode the href attribute of the hyperlink. In summary, the HrefEncode method makes sure the URL does not have invalid characters such as spaces or accents. You can use this method anywhere you have the href or src attribute. If the URL is valid, then the HrefEncode method does nothing.

The rules for URL encoding specify spaces are not allowed as well as some other characters. Essentially, this method makes sure there are no spaces in the URL. Any space is replaced by the plus sign ('+'), and any other illegal character is encoded into the %xx format.

Since some characters are valid in URLs as delimiters, those characters are left alone. The following characters are not encoded:

Character Description
: Colon
/ Forward Slash
? Question Mark (Query String)
# Number Sign / Hash (Fragment)
& Ampersand
; Semi-colon
, Comma
' Apostrophe
= Equals
+ Plus
@ At
$ Dollar
[ Reserved (see RFC 3986)
] Reserved (see RFC 3986)
( Reserved (see RFC 3986)
) Reserved (see RFC 3986)
* Reserved (see RFC 3986)
! Reserved (see RFC 3986)
. Dot
- Minus
_ Underscore
~ Tide
% Percent. The percent will be encoded to "%25" if not followed by a valid hexadecimal pair.

Any backslash ('\') found before the query string ('?') or the fragment ('#') will be converted to a forward slash, otherwise they will be percent-encoded to "%5C".

Usage:
You can use the HrefEncode method to create an hyperlink.


strURL = "myfile.htm"
Report.Write "<a href='" & Util.HrefEncode(strURL) & "'>Open My File</a>"

Examples:
The following code samples show the differences between HrefEncode and UrlEncode.


strURL = "http://www.genopro.com/"

Report.WriteBr Util.HrefEncode(strURL)
' Output: http://www.genopro.com/

Report.WriteBr Util.UrlEncode(strURL)
' Output: http%3A%2F%2Fwww%2Egenopro%2Ecom%2F


strURL = "http://www.genopro.com/?name=André & Hélène;condition=(x+y/z%w)>99"

Report.WriteBr Util.HrefEncode(strURL)
' Output: http://www.genopro.com/?name=Andr%C3%A9+&+H%C3%A9l%C3%A8ne;condition=(x+y/z%25w)%3E99

Report.WriteBr Util.UrlEncode(strURL)
' Output: http%3A%2F%2Fwww%2Egenopro%2Ecom%2F%3Fname%3DAndr%C3%A9+%26+H%C3%A9l%C3%A8ne%3Bcondition%3D%28x%2By%2Fz%25w%29%3E99

Unicode Issues:
If the URL contains non-Ascii characters, the string is converted to UTF-8 and before being URL encoded as it is the case of the name "Hélène". The accent "é" is encoded in UTF-8 in two bytes as "é" which is then URL-encoded as "%C3%A9". The UrlEncode method uses the same UTF-8 encoding for non-Ascii URLs.

Reference:
For URI syntax encoding, please visit http://www.ietf.org/rfc/rfc3986.txt.

See Also:
UrlEncode
FormatString
 

 

Copyright © 1998-2014. All rights reserved. GenoPro® and the GenoPro logo are registered trademarks.