Solved

get first 20 characters

Posted on 1999-01-28
7
178 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
Comment Utility
$test = substr "thisisaverygoodtestofthisapp",0,20;
0
 

Author Comment

by:lweiner
Comment Utility
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
Comment Utility
That should work just fine.

Martin
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:lweiner
Comment Utility
It shoudl, but it it doesn't.
0
 
LVL 4

Expert Comment

by:martinag
Comment Utility
It does for me.
Maybe you could post your code?

Martin
0
 
LVL 2

Accepted Solution

by:
tpryor earned 120 total points
Comment Utility
$sub = substr( $test, 0, 20 );
0
 
LVL 84

Expert Comment

by:ozo
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

772 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

13 Experts available now in Live!

Get 1:1 Help Now