15.04.2018 Views

programming-for-dummies

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

432<br />

Searching Phonetically<br />

Basically, the Soundex algorithm converts each string into a numeric code<br />

that begins with the first letter of the string. So if you had the name Harry,<br />

the Soundex algorithm might convert that name into the code H600 by following<br />

these steps:<br />

1. Capitalize all letters in the string.<br />

2. Retain the first letter of the word.<br />

3. Change all occurrences of the following letters to 0 (zero):<br />

A, E, I, O, U, H, W, Y<br />

4. Replace any letters with the following numbers:<br />

1 = B, F, P, V<br />

2 = C, G, J, K, Q, S, X, Z<br />

3 = D, T<br />

4 = L<br />

5 = M, N<br />

6 = R<br />

5. Replace all pairs of identical digits with a single digit, such as replacing<br />

66 with just 6.<br />

6. Remove all zeros from the string.<br />

7. Pad the string with trailing zeros so the entire Soundex code consists<br />

of the following <strong>for</strong>mat:<br />

<br />

Table 3-2 shows how the Soundex algorithm calculates identical Soundex<br />

codes <strong>for</strong> the strings Harry and Hairy.<br />

Table 3-2<br />

Calculating a Soundex Code<br />

Soundex Algorithm Step String #1 (Harry) String #2 (Hairy)<br />

1 HARRY HAIRY<br />

2 H H<br />

3 H0RR0 H00R0<br />

4 H0660 H0060<br />

5 H060 H060<br />

6 H6 H6<br />

7 H600 H600

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!