Way to Seperate words.

gerry.odea
Posts: 98
Joined: Fri Sep 19, 2008 9:33 am

Way to Seperate words.

Post by gerry.odea »

Is there a way to break apart a word? For instance if I had a variable called $username and its value was "Gerry". I want to be able to take "Gerry" apart and assign a variable for each letter for instance
$letter1=G
$letter2=e
$letter3=r
$letter4=r
$letter5=y
$letter6=""
$letter7=""
$letter8=""
etc
User avatar
John
Site Admin
Posts: 2625
Joined: Mon Apr 24, 2000 3:18 pm
Location: Cleveland, OH

Way to Seperate words.

Post by John »

Yes, assuming you have those variables already declared in the script:

<rex "." $username>
<$letters=$ret>
<loop $letters>
<strfmt "letter%d" $next>
<$varname=$ret>
<setvar $varname $letters>
</loop>
John Turnbull
Thunderstone Software
gerry.odea
Posts: 98
Joined: Fri Sep 19, 2008 9:33 am

Way to Seperate words.

Post by gerry.odea »

I used this one.
<if $user_name neq "">
<rex "." $user_name>
<$letters=$ret>
<$colors = blue yellow red green>
<Loop $letters $colors>
<if $letters=" "><$letters=blank></if>
<fmt '<img src=/i/letters/%s%s.gif height=30 width=20 border=0 alt=%s>'$colors $letters $user_name>
</loop>

The problem is that once all the colors in the variable $colors are used up then it stops. How can I make it repeat the colors in the same sequence and only stop once all the variables in $letters are used up. And Thank you John for the previous answer.
gerry.odea
Posts: 98
Joined: Fri Sep 19, 2008 9:33 am

Way to Seperate words.

Post by gerry.odea »

I did this and it works but is there any cleaner way to do it?

<if $user_name neq "">
<rex "." $user_name>
<$letters=$ret>
<loop $letters>
<if $letters=" "><$letters=blank></if>
<$colors = blue yellow red green>
<loop max=1 skip=$skipnum $colors>
<fmt '<img src=/i/letters/%s%s.gif height=30 width=20 border=0 alt=%s>'$colors $letters $user_name>
<$skipnum=$next>
<if $skipnum = 4><$skipnum=0><$next=0></if>
</loop>
</loop>
<else>
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

Way to Seperate words.

Post by mark »

This is the same idea but slightly more compact.
Side note, you may not want the full user name as alt
text for every image. Either use the full name once for the first image and empty for the rest or just the letter for each. It could be very messy in text otherwise.

<rex "." $user_name>
<$letters=$ret>
<$colors = blue yellow red green>
<count $colors>
<$ncolors=$ret>
<loop $letters>
<if $letters=" "><$letters=blank></if>
<$skipnum=(fmod($loop,$ncolors))>
<loop max=1 skip=$skipnum $colors>
<fmt '<img src=/i/letters/%s%s.gif height=30 width=20 border=0 alt=%s>\n'$colors $letters $user_name>
</loop>
</loop>