Forum Moderators: coopster & phranque

Message Too Old, No Replies

displaying portions of a string

         

lindajames

10:14 pm on Mar 31, 2003 (gmt 0)

10+ Year Member



Hello everyone, I have the code below that is in a script i have and basically this code is used to display the customers password:

$str = "$r{'passwd'}";
if ($str eq undef) { $str = " "; }
bodyprint("<td>$str</td>");

At the moment it displays the customers full password and I want it to just display the first two characters of the password. Can anyone tell me how this can be done?

Any suggestions would be much appreciated.

Cheers
Linda

xunker

10:23 pm on Mar 31, 2003 (gmt 0)

10+ Year Member



If perl, try the substr keyword ([perldoc.com ]). On the botton you may try something like:


$trunc_str = substr ($str, 0, 2);
bodyprint ("<td>$trunc_str</td>");

lindajames

10:42 pm on Mar 31, 2003 (gmt 0)

10+ Year Member



thanx xunker, it worked. how about if i wanted the first and last characters of the password? can you tell me how i would do that?

cheers
linda

andreasfriedrich

11:10 pm on Mar 31, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just use a negative offset as explained in the substr [perldoc.com] documentation.


substr [perldoc.com] $string, -1 , 1

will return the last character.

Andreas