fork download
  1. str = "STAY HUNGRY, STAY FOOLISH";
  2. dictionary = get_csv_data("gutenberg.csv");
  3. show_char_index(str,dictionary);
  4.  
  5. function show_char_index(str,dictionary)
  6. {
  7. for(var i = 0; i < str.length; i++)
  8. {
  9. var pos = dictionary[str.charAt(i)];
  10. WScript.Echo(pos.X + "," + pos.Y);
  11. }
  12. }
  13.  
  14. function get_csv_data( csv_path )
  15. {
  16. var arr_data = [];
  17.  
  18. var fso = WScript.CreateObject("Scripting.FileSystemObject");
  19. var txt_r = fso.OpenTextFile( csv_path, 1 );
  20. var line = "";
  21. var arr_line_data;
  22. for(var i = 0; ! txt_r.AtEndOfStream; i++ )
  23. {
  24. line = txt_r.ReadLine();
  25. arr_line_data = parse_csv_line(line);
  26. for(var j = 0; j < arr_line_data.length; j++)
  27. {
  28. var c = arr_line_data[j];
  29. arr_data[c] = new Postion(j,i);
  30. }
  31. }
  32. txt_r.Close();
  33. fso = null;
  34.  
  35. return arr_data;
  36. }
  37.  
  38. function parse_csv_line(line)
  39. {
  40. result = new Array();
  41. for(var i = 0; i < line.length;)
  42. {
  43. if(line.charAt(i) == '\"')
  44. {
  45. i++;
  46. do{
  47. result.push(line.charAt(i));
  48. i++;
  49. }while(line.charAt(i) != '\"');
  50. }
  51. i++;
  52. }
  53. return result;
  54. }
  55.  
  56. function Postion(x,y)
  57. {
  58. this.X = x;
  59. this.Y = y;
  60. }
  61.  
Runtime error #stdin #stdout #stderr 0.02s 4936KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog.js:18: ReferenceError: WScript is not defined