Solved

How to shorten a to long name?

Posted on 1998-11-21
7
165 Views
Last Modified: 2010-03-04
It should do the following:
e.g.


old name >> thisnameistolong

names longer than 10 should be converted in >> thisnameis..


if(length($name) > 10) {

$name = ?;

}


Regards,

Bigi
0
Comment
Question by:Bigi
  • 4
  • 2
7 Comments
 
LVL 4

Expert Comment

by:martinag
ID: 1206427
$name = substr($name,0,10) if length($name) > 10;

Martin
0
 
LVL 4

Expert Comment

by:martinag
ID: 1206428
I didn't see the two spots. Add using ."..":
$name = substr($name,0,10).".." if length($name) > 10;

Martin
0
 

Author Comment

by:Bigi
ID: 1206429
Thanks!

How can I grade it?

Please reply with "answer" (not comment) so I can send
you the points.

Regards,

Bigi
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 4

Accepted Solution

by:
martinag earned 80 total points
ID: 1206430
$name = substr($name,0,10).".." if length($name) > 10;

Martin
0
 

Author Comment

by:Bigi
ID: 1206431
Adjusted points to 80
0
 
LVL 4

Expert Comment

by:martinag
ID: 1206432
Thanks.

Martin
0
 
LVL 84

Expert Comment

by:ozo
ID: 1206433
#or
substr($name,10)='..'
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
.properties file to call function/method 9 61
Perl regex to replace any capital letters not preceded by ">" 6 121
Perl Frameworks 1 90
Perl File::Find alternative 1 70
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

809 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