Table formatting script - 17/02/04 06:36 PM
I thought this would come in very handy, so I whipped it up in my spare time.
$table(data) // Use that to call the alias.
The data should be formatted in this manner:
Name[td]Address[td]City[td]Phone[tr]teh-awpZor[td]#script[td]GameSurge[td]1-800-GETALIFE
where [td] means new column and [tr] means new row.
[td] [td] [td] [td]
[tr] Name Address City Phone
[tr] teh-awpZor #script GameSurge 1-800-GETALIFE
The information returned will look like this:
Name Address City Phone[tr]teh-awpZor #script GameSurge 1-800-GETALIFE
which when broken down will be:
Name Address City Phone
teh-awpZor #script GameSurge 1-800-GETALIFE
alias table {
; // Changes [tr] and [td] into single, easiliy distinguished characters
var %i = $replace($remove($1-,$chr(157),$chr(158)),[tr],$chr(157),[td],$chr(158))
; // Establishes the length for 9 columns
var %col = 0 0 0 0 0 0 0 0 0
var %x = 0
; // Establishes the longest possible length for each column.
while (%x < $gettok(%i,0,157)) {
inc %x | var %y = 0
while (%y < $gettok($gettok(%i,%x,157),0,158)) {
inc %y
if ($len($gettok($gettok(%i,%x,157),%y,158)) > $gettok(%col,%y,32)) var %col = $puttok(%col,$($len($gettok($gettok(%i,%x,157),%y,158))),%y,32)
}
}
; // Modifies the length of each column in each row to be exact to other cells in the same column. Then expands those column lengths by 2 non-breaking characters.
var %x = 0
while (%x < $gettok(%i,0,157)) {
inc %x | var %y = 0 | var %z = $gettok(%i,%x,157)
while (%y < $gettok($gettok(%i,%x,157),0,158)) {
inc %y
var %c = $calc($gettok(%col,%y,32) - $len($gettok($gettok(%i,%x,157),%y,158)) + 2)
var %z = $puttok(%z,$($gettok(%z,%y,158) $+ $str($chr(160),%c)),%y,158)
}
var %i = $puttok(%i,%z,%x,157)
}
; // Removes unnecessary [tr] markers.
var %i = $iif($left(%i,1) == $chr(157),$right(%i,-1),%i) | var %i = $iif($right(%i,1) == $chr(157),$left(%i,-1),%i)
; // Replaces [tr] substitute characters with '[tr]'
return $remove($replace(%i,$chr(157),[tr]),$chr(158))
}
*Note: Do not pass ascii character 157 OR 158 through the alias, you won't get them back :o.
*Note: The alias will work for UP TO 9 rows. If you feel you'll need more add more 0's to var %col separated by a space. e.g. '0 0 0 0 0'
<teh-awpZor> yep, I like it. Hope you do too.
$table(data) // Use that to call the alias.
The data should be formatted in this manner:
Name[td]Address[td]City[td]Phone[tr]teh-awpZor[td]#script[td]GameSurge[td]1-800-GETALIFE
where [td] means new column and [tr] means new row.
[td] [td] [td] [td]
[tr] Name Address City Phone
[tr] teh-awpZor #script GameSurge 1-800-GETALIFE
The information returned will look like this:
Name Address City Phone[tr]teh-awpZor #script GameSurge 1-800-GETALIFE
which when broken down will be:
Name Address City Phone
teh-awpZor #script GameSurge 1-800-GETALIFE
alias table {
; // Changes [tr] and [td] into single, easiliy distinguished characters
var %i = $replace($remove($1-,$chr(157),$chr(158)),[tr],$chr(157),[td],$chr(158))
; // Establishes the length for 9 columns
var %col = 0 0 0 0 0 0 0 0 0
var %x = 0
; // Establishes the longest possible length for each column.
while (%x < $gettok(%i,0,157)) {
inc %x | var %y = 0
while (%y < $gettok($gettok(%i,%x,157),0,158)) {
inc %y
if ($len($gettok($gettok(%i,%x,157),%y,158)) > $gettok(%col,%y,32)) var %col = $puttok(%col,$($len($gettok($gettok(%i,%x,157),%y,158))),%y,32)
}
}
; // Modifies the length of each column in each row to be exact to other cells in the same column. Then expands those column lengths by 2 non-breaking characters.
var %x = 0
while (%x < $gettok(%i,0,157)) {
inc %x | var %y = 0 | var %z = $gettok(%i,%x,157)
while (%y < $gettok($gettok(%i,%x,157),0,158)) {
inc %y
var %c = $calc($gettok(%col,%y,32) - $len($gettok($gettok(%i,%x,157),%y,158)) + 2)
var %z = $puttok(%z,$($gettok(%z,%y,158) $+ $str($chr(160),%c)),%y,158)
}
var %i = $puttok(%i,%z,%x,157)
}
; // Removes unnecessary [tr] markers.
var %i = $iif($left(%i,1) == $chr(157),$right(%i,-1),%i) | var %i = $iif($right(%i,1) == $chr(157),$left(%i,-1),%i)
; // Replaces [tr] substitute characters with '[tr]'
return $remove($replace(%i,$chr(157),[tr]),$chr(158))
}
*Note: Do not pass ascii character 157 OR 158 through the alias, you won't get them back :o.
*Note: The alias will work for UP TO 9 rows. If you feel you'll need more add more 0's to var %col separated by a space. e.g. '0 0 0 0 0'
<teh-awpZor> yep, I like it. Hope you do too.