Forum Moderators: coopster

Message Too Old, No Replies

how to increase a variable with letters

         

UnikRasu

9:58 pm on Dec 11, 2002 (gmt 0)

10+ Year Member



how shall i do if i want to make this funktionable

$x = "a";
$x = $a++;

i want to make a character increeses its value every time i loop my script i know the loop but i dont know the increase letters

amoore

12:17 am on Dec 12, 2002 (gmt 0)

10+ Year Member



I'm not sure I understand what you want to get in return. You don't define $a at all and then you increment it. Do you want something that turns an "a" into "b" and a "w" into "x" and so forth? What does it do to "z"? how about "Z"? what about "4" or "gravy"?

Is this perl or PHP?

You might want to convert the character into its ASCII code, increment that, possibly subtract 26 or 52 or 62, and convert back to a character. I'm not sure what you'll do about strings that are more than one character, or are not ASCII characters (do you want UTF-8 or anything?).

Hope it helps you think a little more about what you are actually looking for.

kenta

12:24 am on Dec 12, 2002 (gmt 0)

10+ Year Member



I'm reading it UnikRasu wanting to increase letters each time. Starting at "a" the next character would be "b" and so on and so on.

My suggestion, put all the letters in an array. THEN refer to the array with a number. In the case below 0 = a, 1 = b, etc...

EXAMPLE:


#!/usr/bin/perl

#define your arrary of letters
@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");

#This will just print all the letters
while ($counter <= 25) {
print "$letters[$counter]\n";
$counter++;
}

That help?

UnikRasu

4:11 pm on Dec 12, 2002 (gmt 0)

10+ Year Member



no it is php

and i want to make a script that makes a variable that have a value of a to gett every letter to z like i can gett 1 and evre nubers to 20 for example for the numbrers i do like this

$a = 1;
do {
echo "here is $a";
echo "<br>;
$a = $a++;
=while($a<=20);

how does i do so a letter can be from a to z?

seindal

4:15 pm on Dec 12, 2002 (gmt 0)

10+ Year Member



Kenta: in perl you can autoincrement strings!

Try

$a = "aaa";
$a++;
print $a;

It prints aab

Don't know about php, though.

René.

UnikRasu

5:18 pm on Dec 12, 2002 (gmt 0)

10+ Year Member



thanks it works

kenta

1:01 am on Dec 13, 2002 (gmt 0)

10+ Year Member



Doh!. René, I thought I tried that it came out wrong so I just did it the other way :) Leave it to me to make more work for myself.

seindal

1:19 am on Dec 13, 2002 (gmt 0)

10+ Year Member



I once read almost the entire perl documention, and this thing remained because I found it so weird. I have never ever used it in a real program!