Click here to Skip to main content
15,893,668 members
Articles / Programming Languages / VBScript

Calling scripts within scripts

Rate me:
Please Sign up or sign in to vote.
4.40/5 (5 votes)
29 Jan 2000CPOL 158K   1K   43  
A Component for calling a URL from an ASP script and reading back the output
// ###########################################################################
// #
// # file:
// #	url_encode_decode.cpp
// #
// ###########################################################################

#include "stdafx.h"
#pragma warning(disable:4786)
#include "url_encode_decode.h"

#ifdef _DEBUG
	#define new DEBUG_NEW
	#undef THIS_FILE
	static char THIS_FILE[] = __FILE__;
#endif


//////////////////////////////////////////////////////////////////////////////
// encoding and decoding of the charactes in an url.

const char* encoded[] = {
	"%00",
	"%01",
	"%02",
	"%03",
	"%04",
	"%05",
	"%06",
	"%07",
	"%08",
	"%09",
	"%0A",
	"%0B",
	"%0C",
	"%0D",
	"%0E",
	"%0F",
	"%10",
	"%11",
	"%12",
	"%13",
	"%14",
	"%15",
	"%16",
	"%17",
	"%18",
	"%19",
	"%1A",
	"%1B",
	"%1C",
	"%1D",
	"%1E",
	"%1F",
	"+",
	"%21",
	"%22",
	"%23",
	"%24",
	"%25",
	"%26",
	"%27",
	"%28",
	"%29",
	"%2A",
	"%2B",
	"%2C",
	"%2D",
	"%2E",
	"%2F",
	"0",
	"1",
	"2",
	"3",
	"4",
	"5",
	"6",
	"7",
	"8",
	"9",
	"%3A",
	"%3B",
	"%3C",
	"%3D",
	"%3E",
	"%3F",
	"%40",
	"A",
	"B",
	"C",
	"D",
	"E",
	"F",
	"G",
	"H",
	"I",
	"J",
	"K",
	"L",
	"M",
	"N",
	"O",
	"P",
	"Q",
	"R",
	"S",
	"T",
	"U",
	"V",
	"W",
	"X",
	"Y",
	"Z",
	"%5B",
	"%5C",
	"%5D",
	"%5E",
	"%5F",
	"%60",
	"a",
	"b",
	"c",
	"d",
	"e",
	"f",
	"g",
	"h",
	"i",
	"j",
	"k",
	"l",
	"m",
	"n",
	"o",
	"p",
	"q",
	"r",
	"s",
	"t",
	"u",
	"v",
	"w",
	"x",
	"y",
	"z",
	"%7B",
	"%7C",
	"%7D",
	"%7E",
	"%7F",
	"%80",
	"%81",
	"%82",
	"%83",
	"%84",
	"%85",
	"%86",
	"%87",
	"%88",
	"%89",
	"%8A",
	"%8B",
	"%8C",
	"%8D",
	"%8E",
	"%8F",
	"%90",
	"%91",
	"%92",
	"%93",
	"%94",
	"%95",
	"%96",
	"%97",
	"%98",
	"%99",
	"%9A",
	"%9B",
	"%9C",
	"%9D",
	"%9E",
	"%9F",
	"%A0",
	"%A1",
	"%A2",
	"%A3",
	"%A4",
	"%A5",
	"%A6",
	"%A7",
	"%A8",
	"%A9",
	"%AA",
	"%AB",
	"%AC",
	"%AD",
	"%AE",
	"%AF",
	"%B0",
	"%B1",
	"%B2",
	"%B3",
	"%B4",
	"%B5",
	"%B6",
	"%B7",
	"%B8",
	"%B9",
	"%BA",
	"%BB",
	"%BC",
	"%BD",
	"%BE",
	"%BF",
	"%C0",
	"%C1",
	"%C2",
	"%C3",
	"%C4",
	"%C5",
	"%C6",
	"%C7",
	"%C8",
	"%C9",
	"%CA",
	"%CB",
	"%CC",
	"%CD",
	"%CE",
	"%CF",
	"%D0",
	"%D1",
	"%D2",
	"%D3",
	"%D4",
	"%D5",
	"%D6",
	"%D7",
	"%D8",
	"%D9",
	"%DA",
	"%DB",
	"%DC",
	"%DD",
	"%DE",
	"%DF",
	"%E0",
	"%E1",
	"%E2",
	"%E3",
	"%E4",
	"%E5",
	"%E6",
	"%E7",
	"%E8",
	"%E9",
	"%EA",
	"%EB",
	"%EC",
	"%ED",
	"%EE",
	"%EF",
	"%F0",
	"%F1",
	"%F2",
	"%F3",
	"%F4",
	"%F5",
	"%F6",
	"%F7",
	"%F8",
	"%F9",
	"%FA",
	"%FB",
	"%FC",
	"%FD",
	"%FE",
	"%FF" };

std::string UrlEncode( const char* _input )
{
	const std::string input(_input);
	std::string output;

	for ( int i=0; i<input.size(); ++i )
		output += encoded[input[i]];

	return output;
}

std::string UrlDecode( const char* _input )
{
	const std::string input(_input);
	std::string output;
	std::string tmp;

	for ( int i=0; i<input.size(); ++i ) {

		// an encoded char.
		if ( input[i]=='%' ) {
			tmp = input.substr(i,3);

			// array contains upper-cases.
			tmp[1] = _toupper(tmp[1]);
			tmp[2] = _toupper(tmp[2]);

			// look whole array to find match.
			for ( int j=0; j<sizeof encoded/sizeof encoded[0]; ++j ) {
				if ( encoded[j]==tmp ) {
					output += j;
					break;
				}
			}

		// a non-encoded char.
		} else
			output += input[i];
	}

	return output;
}


//////////////////////////////////////////////////////////////////////////////

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer Zeta Software GmbH
Germany Germany
Uwe does programming since 1989 with experiences in Assembler, C++, MFC and lots of web- and database stuff and now uses ASP.NET and C# extensively, too. He has also teached programming to students at the local university.

➡️ Give me a tip 🙂

In his free time, he does climbing, running and mountain biking. In 2012 he became a father of a cute boy and in 2014 of an awesome girl.

Some cool, free software from us:

Windows 10 Ereignisanzeige  
German Developer Community  
Free Test Management Software - Intuitive, competitive, Test Plans.  
Homepage erstellen - Intuitive, very easy to use.  
Offline-Homepage-Baukasten

Comments and Discussions