Solved

get first 20 characters

Posted on 1999-01-28
7
198 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

776 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