Link to home
Start Free TrialLog in
Avatar of lweiner
lweiner

asked on

get first 20 characters

I want to get the first 20 characters of a string...For example:

$test = "thisisaverygoodtestofthisapp"

I want something that makes $test = to the first 20 characters of that string.

Thanks.
Avatar of ozo
ozo
Flag of United States of America image

$test = substr "thisisaverygoodtestofthisapp",0,20;
Avatar of lweiner
lweiner

ASKER

How does this work with variables, for example what I would want to do is:

$test = substr $test ,0,20;


That should work just fine.

Martin
Avatar of lweiner

ASKER

It shoudl, but it it doesn't.
It does for me.
Maybe you could post your code?

Martin
ASKER CERTIFIED SOLUTION
Avatar of tpryor
tpryor

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Are you still using Perl4, which requires using the parenthesis?
(if so, it might help to mention when your question is about an obsolete language:-)

But if are using Perl4, another way to do it could be:
  substr($test,20)= '';
(In Perl5, this would be an error if $test had less than 20 characters)