There are certain reserved characters in the URL which are encoded. If you are composing a string which is part of the URL, the reserved characters must be removed or replaced. The characters which are encoded in the URL are :, /, #, ?, &, @, %,+,<space>.

All characters except space can be removed. Space can be replaced with a dash.

While replacing space with – (dash), there is a possibility of having consecutive dashes in the URL. The Regular expression “-{2,}” captures consecutive dashes. This can be replaced by a single dash using the Replace method of Regex class.

Removing reserved characters while preparing a string which is part of the URL

Leave a Reply

Your email address will not be published. Required fields are marked *