The Code
By looking at book titles as a template, code can automate shortening
the titles. In many cases they follow this pattern:
[short title]:[sub title]([series title])
Using string-dicing functions built into most languages for trimming
is easy work.
- JavaScript
var title = "Malicious Mobile Code: Virus Protection for Windows";
shortTitle = title.split(":")
alert(shortTitle[0]);
- Perl
my $title = "Malicious Mobile Code: Virus Protection for Windows";
@shortTitle = split /:/, $title;
print $shortTitle[0];
- VBScript
strTitle = "Malicious Mobile Code: Virus Protection for Windows"
shortTitle = Split(strTitle,":")
Wscript.Echo shortTitle(0)
- PHP
$title = "Malicious Mobile Code: Virus Protection for Windows";
$shortTitle = split(":",$title);
echo $shortTitle[0];
- Python
import string
title = "Malicious Mobile Code: Virus Protection for Windows";
shortTitle = string.split(title,":");
print shortTitle[0];
Each of these bits of code splits the string at the colon (:) and prints everything before it (i.e.,
Malicious Mobile Code). These code snippets
would work with books that don't have colons as well by returning the
entire title.