?
Solved

get first 20 characters

Posted on 1999-01-28
7
Medium Priority
?
224 Views
Last Modified: 2010-03-05
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
Comment
Question by:lweiner
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 1210342
$test = substr "thisisaverygoodtestofthisapp",0,20;
0
 

Author Comment

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

$test = substr $test ,0,20;


0
 
LVL 4

Expert Comment

by:martinag
ID: 1210344
That should work just fine.

Martin
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:lweiner
ID: 1210345
It shoudl, but it it doesn't.
0
 
LVL 4

Expert Comment

by:martinag
ID: 1210346
It does for me.
Maybe you could post your code?

Martin
0
 
LVL 2

Accepted Solution

by:
tpryor earned 480 total points
ID: 1210347
$sub = substr( $test, 0, 20 );
0
 
LVL 84

Expert Comment

by:ozo
ID: 1210348
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question