Solved

get first 20 characters

Posted on 1999-01-28
7
189 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 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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 120 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 …
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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

895 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now