Forum Discussion

kluo's avatar
kluo
Occasional Contributor
13 years ago

Strange Characters for the first column name in a CSV file

Hello,



When I ran attached MyScript I alwasy encountered the following message 'Parameter name does not exist';



I double checked the .CSV file with NotePad and Excel, I did see the 1st column's name is "Display Name", I did not see any unusual;

But when I use the TestComplete Debug Tool to analysis, I noticed the Value of that Column Name TestComplete captured was "Display Name", it made me confused, for more info, pls. refer to attached .JPG.



Could anybody help to explain what happened and how to deal with this case? I check the othere Columns, and all of them works well.

Which means the value of the first column's Name is so special and strange.





Thanks,

Kevin

4 Replies

  • Hi,



    If you look at your file's contents in any editor which allows viewing text files in hex, you'll see 'Ï»¿' in its first bytes. The MS Jet engine reads them and passes them to TC when you access your file. This is because your file is saved in UTF-8.

    Try opening it in Excel and saving as 'CSV (MS-DOS)'.
  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor
    You could also edit in NotePad and make sure you save the CSV file as ANSI.  That will correct this as well.
  • kluo's avatar
    kluo
    Occasional Contributor
    Hello Jared and Robert,



    Thank you, so now we know where this BOM Characters comes from. The .CSV file is saved by default in UTF-8 from our product which we are going to test.



    Except using external tool like notepad or Excel, is there any internal tool or function which we can use to do such convertion? Or is that any method which we could use to bypass such issue? Pls. advise.



    Thanks,

    Kevin

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3
    Hi Kevin,



    The code like below might help...

    [convertToASCII.js]

    var fileName = "C:\\Tests\\MyTest\\MyTestProject\\Script\\myScript.sj";



    if (isUnicode(fileName))

    {

      var fso = new ActiveXObject("Scripting.FileSystemObject");

      var aFile = fso.OpenTextFile(fileName, 1, false, -1);

      var text = aFile.ReadAll();

      aFile.Close();

      aFile = fso.CreateTextFile(fileName, true, false);

      aFile.Write(text);

      aFile.Close();

    }

    //-----------------------------------------------------------------------------



    function isUnicode(fileName)

    {

      var fso = new ActiveXObject("Scripting.FileSystemObject");

      var aFile = fso.OpenTextFile(fileName, 1, false, 0);

      var flag = aFile.Read(2)

      aFile.Close();

      var template = String.fromCharCode(1103, 1102);

      if (flag == template) return true;

      return false;

    }

    //-----------------------------------------------------------------------------