Welcome to the Second Life Forums Archive

These forums are CLOSED. Please visit the new forums HERE

alphabet to number and back?

Yamil Dagger
Registered User
Join date: 10 Jul 2007
Posts: 36
05-06-2008 04:31
Hello guys. I'm working on a new project and it's hard to explain why but is there any simply way of turning a letting into a number and a number into a letter? Like I want to be able to turn "c" into 3 since it's the 3rd letter. 7 into G since g is the 7th letter of the alphabet...ect.
I know i can do it by listing all 26 letters and stuff but is there some easy to use command for converting that I don't know about?
Kei Manamiko
Registered User
Join date: 10 Apr 2008
Posts: 6
05-06-2008 05:21
Not that I know...if you cast a character (not numeric) to an integer it retursn zero.

Despites the lack of memory that can generate...the use of a list to store 26 elemnts is not taht ackward.
Yamil Dagger
Registered User
Join date: 10 Jul 2007
Posts: 36
05-06-2008 14:16
well storing 26 elements in a wall of about 50 objects each with that script does make a difference. Thats ok I'll find a way around it.
Xhawkx Holden
Registered User
Join date: 1 Nov 2006
Posts: 86
05-06-2008 19:46
Something like this should work...
Not in SL right now to test it..


Integer Function LetterToNumber(String incomingLetter)
{
list letters=["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"];
return llSubStringIndex(letters,incomingLetter)+1;
}
Winter Ventura
Eclectic Randomness
Join date: 18 Jul 2006
Posts: 2,579
05-06-2008 23:06
you can do the same thing with a string...

string alphabet = "_abcdefghijklmnopqrstuvwxyz";
integer number = llSubStringIndex(alphabet, letter);

A cute trick is to waste a character at the front of the string, or list, so that "a" = position 1, rather than position "0"
_____________________

● Inworld Store: http://slurl.eclectic-randomness.com
● Website: http://www.eclectic-randomness.com
● Twitter: @WinterVentura