asc

asc
int asc(string char)

Documentation

Pass a one character string, returns the ascii value. This is not very fast, so don't overuse it. I've provided a binary version as well now, should be faster. This function is obsolete. Use the builtin Verge3 asc() instead.

Example Usage

int asc(string char)
// Pass: A one character string
// Return: The ascii value of the chr, 0 on fail
// Credit: pelican
{
	int c;
	int i = 128;
	int x = 128;
	while (i)
	{
		c = strcmp(char, chr(x));
		if (!c) return x;
		i = i>>1;
		x += c * i;
	}
	return 0;
}


int asc(string char)
// Pass: A one character string
// Return: The ascii value of the chr, 0 on fail
// Assmes: Passed string is one character exactly
{
	int i;
	for (i = 1; i < 256; i++)
	{
		// To optimise, create an array[256] and sort
		// front to back by commonest occurence
		if(!strcmp(char, chr(i))) return i;
	}
	return 0;
}
Talkback

There are no talkbacks on this documentation page yet. Post the first?

Post a new comment?

Doc Nav

Your docs
View All Docs

If you log in, you can edit the documentation, or create your own documents and tutorials!

Ben McGraw's lovingly crafted this website from scratch for years.
It's a lot prettier this go around because of Jon Wofford.
Verge-rpg.com is a member of the lunarnet irc network, and would like to take this opportunity to remind you that regardless how babies taste, it is wrong to eat them.