PDA

View Full Version : Passing each .charAt() value as an array to a function


Chimera
05-31-2003, 07:20 AM
Inside a function I have filled local arrays a[0-19] .. z[0-20] (aswell as ones for numbers etc.) with data.
I'd like to call a separate function to add to data in the global line[] array with the array data of the character from inputText but how do I pass each character as an array without having to repeat the lines as I have with numbers?

line = New array(20);

function font1(inputText) {
..array data..
for(i=0; i < inputText.length; i++) {
var currchar = inputText.charAt(i);
if(currchar == "@") line = dolines(at,20)
else if(currchar == ".") line = dolines(fs,20)
else if(currchar == "0") line = dolines(zero,20)
else if(currchar == "1") line = dolines(one,20)
else if(currchar == "2") line = dolines(two,20)
else if(currchar == "3") line = dolines(three,20)
else if(currchar == "4") line = dolines(four,20)
else if(currchar == "5") line = dolines(five,20)
else if(currchar == "6") line = dolines(six,20)
else if(currchar == "7") line = dolines(seven,20)
else if(currchar == "8") line = dolines(eight,20)
else if(currchar == "9") line = dolines(nine,20)
else line = dolines(currchar,20);
}
..code to ouput line[] array..
}

function dolines(currchar,nl)
{
for(i=0; i<=nl; i++) {
line[i] += currchar[i];
}
return line;
}

or if there's an even better way someone can think of doing this..?

joh6nn
06-02-2003, 03:24 AM
can we see the page this is on? there may be a couple of ways of working this out, but we'd need a bit more information than just what's here

Chimera
06-02-2003, 10:00 AM
This code is only in it's infancy, there is a fair amount I need to do before I even think about putting it on a site (like replacing dummy data with real data).
The way it was working before I tried to optimise the code was having line0 to line19 as a local standard variables that get added to in all 40 or so if else statements inside each of the planned 10 font() functions, which seems a bit bloated.
As it stands it isn't working, since it is passing the string "a" to the dolines function when I want it to pass the entire a[] array. I'm not sure if that can be done easily though. I read a few things in searching for an answer about using eval() or assign methods, but also read that they should be avoided. Note: each font will likely have a different number of line variables.

joh6nn
06-03-2003, 12:36 AM
i really think we need to see all the code you've got so far, and a more detailed description of what it is you're trying to do. otherwise, i really don't know what it is you're trying to do, or how to help.