Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

get first 20 characters

Posted on 1999-01-28
7
Medium Priority
?
228 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
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 85

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 85

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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

963 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