[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 231
  • Last Modified:

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.
0
lweiner
Asked:
lweiner
  • 2
  • 2
  • 2
  • +1
1 Solution
 
ozoCommented:
$test = substr "thisisaverygoodtestofthisapp",0,20;
0
 
lweinerAuthor Commented:
How does this work with variables, for example what I would want to do is:

$test = substr $test ,0,20;


0
 
martinagCommented:
That should work just fine.

Martin
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
lweinerAuthor Commented:
It shoudl, but it it doesn't.
0
 
martinagCommented:
It does for me.
Maybe you could post your code?

Martin
0
 
tpryorCommented:
$sub = substr( $test, 0, 20 );
0
 
ozoCommented:
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)
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now