str = "STAY HUNGRY, STAY FOOLISH";
dictionary = get_csv_data("gutenberg.csv");
show_char_index(str,dictionary);
function show_char_index(str,dictionary)
{
for(var i = 0; i < str.length; i++)
{
var pos = dictionary[str.charAt(i)];
WScript.Echo(pos.X + "," + pos.Y);
}
}
function get_csv_data( csv_path )
{
var arr_data = [];
var fso = WScript.CreateObject("Scripting.FileSystemObject");
var txt_r = fso.OpenTextFile( csv_path, 1 );
var line = "";
var arr_line_data;
for(var i = 0; ! txt_r.AtEndOfStream; i++ )
{
line = txt_r.ReadLine();
arr_line_data = parse_csv_line(line);
for(var j = 0; j < arr_line_data.length; j++)
{
var c = arr_line_data[j];
arr_data[c] = new Postion(j,i);
}
}
txt_r.Close();
fso = null;
return arr_data;
}
function parse_csv_line(line)
{
result = new Array();
for(var i = 0; i < line.length;)
{
if(line.charAt(i) == '\"')
{
i++;
do{
result.push(line.charAt(i));
i++;
}while(line.charAt(i) != '\"');
}
i++;
}
return result;
}
function Postion(x,y)
{
this.X = x;
this.Y = y;
}
c3RyID0gIlNUQVkgSFVOR1JZLCBTVEFZIEZPT0xJU0giOwpkaWN0aW9uYXJ5ID0gZ2V0X2Nzdl9kYXRhKCJndXRlbmJlcmcuY3N2Iik7CnNob3dfY2hhcl9pbmRleChzdHIsZGljdGlvbmFyeSk7CgpmdW5jdGlvbiBzaG93X2NoYXJfaW5kZXgoc3RyLGRpY3Rpb25hcnkpCnsKCWZvcih2YXIgaSA9IDA7IGkgPCBzdHIubGVuZ3RoOyBpKyspCgl7CgkJdmFyIHBvcyA9IGRpY3Rpb25hcnlbc3RyLmNoYXJBdChpKV07CgkJV1NjcmlwdC5FY2hvKHBvcy5YICsgIiwiICsgcG9zLlkpOwoJfQp9CgpmdW5jdGlvbiBnZXRfY3N2X2RhdGEoIGNzdl9wYXRoICkKewoJdmFyIGFycl9kYXRhID0gW107CgoJdmFyIGZzbyA9IFdTY3JpcHQuQ3JlYXRlT2JqZWN0KCJTY3JpcHRpbmcuRmlsZVN5c3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