Solved

How to shorten a to long name?

Posted on 1998-11-21
7
166 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
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

Title # Comments Views Activity
compress files in RAR using perl 13 84
perl split by | 2 103
add a syntax to a csv file 8 99
what are these modules in perl script 4 103
I've just discovered very important differences between Windows an Unix formats in Perl,at least 5.xx.. MOST IMPORTANT: Use Unix file format while saving Your script. otherwise it will have ^M s or smth likely weird in the EOL, Then DO NOT use m…
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…
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…

828 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