Skip to Main Content
Amazon Hacks
book

Amazon Hacks

by Paul Bausch
August 2003
Intermediate to advanced content levelIntermediate to advanced
304 pages
7h 33m
English
O'Reilly Media, Inc.
Content preview from Amazon Hacks

Make Product Titles Shorter

There are tools for cutting and slicing strings in every programming environment. Here are some quick examples of cutting book titles down to size.

The ProductName that Amazon returns is always the full name of the product. It’s good to be accurate, but sometimes you need only part of the title. For example, O’Reilly has a book called Malicious Mobile Code: Virus Protection for Windows (O’Reilly Computer Security), and this is exactly what Amazon sends as the ProductName value. Weighing in at 80 characters, it’s a bit long when Malicious Mobile Code could work just as well.

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]; ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

From ChatGPT to HackGPT: Meeting the Cybersecurity Threat of Generative AI

From ChatGPT to HackGPT: Meeting the Cybersecurity Threat of Generative AI

Karen Renaud, Merrill Warkentin, George Westerman
Incident Metrics in SRE

Incident Metrics in SRE

Stepan Davidovic

Publisher Resources

ISBN: 0596005423Supplemental ContentCatalog PageErrata