Download ISMAIL

Transcript
Use Case 2: Convert CSV Data into HTML Table (2)
CSV Data
Stu_ID,Stu_Name,Birth_Year,Country,Marital_Status
1001,Nurul Ismail,1983,Malaysia,Married
1009,Nik Ibrahim,1986,Malaysia,Single
The expected output is a set of transformed strings as a HTML table as below:
<table border='1'>
<tr><td>Stu_ID</td><td>Stu_Name</td><td>Birth_Year</td><td>Country</td><td>Marital_Status</td></tr>
<tr><td>1001</td><td>Nurul Ismail</td><td>1983</td><td>Malaysia</td><td>Married</td></tr>
<tr><td>1002</td><td>Yasmeen Al Barak</td><td>1984</td><td>Saudi Arabia</td><td>Married</td></tr>
</table>
Substitution Patterns
1. Substitute the first row (column names)
Match:
(\w+),(\w+),(\w+),(\w+),(\w+)
Replace:
<tr><td>$1</td><td>$2</td><td>$3</td><td>$4</td><td>$5</td>
</tr>
2. Substitute data rows except the first rows
Match:
(\d+),(\w+\s+.*),(\d+),(\w+.*),(\w+)
Replace:
<tr><td>$1</td><td>$2</td><td>$3</td><td>$4</td><td>$5</td>
</tr>
3. Substitute the beginning of the source string with start table tag with border
Match:
^
Replace:
<table border='1'>
4. Substitute the end of the source string with the end table tag
Match:
$
Replace:
</table>
57