Menu

strings spanning multiple lines.

Anonymous
2017-05-30
2017-05-30
  • Anonymous

    Anonymous - 2017-05-30

    Hi Stefan,

    I've been using your ScriptCommunicator for quite some time, and now I have a need to do the following:

    I have a string that has CRLF embedded (\N), example:

    Chemistry: LiPo
    Serial Number: 3755
    Manufacture Date: 2017/5/30
    Num ID Code Rev
    0 &HFFFF 54, 43
    1 &H8325 38, 25
    2 &H8324 38, 25
    3 &H8318 38, 25


    I would like to do something like (can do the below in javascript -but not in qtscript):

    varf myData = Chemistry: LiPo Serial Number: 3755 Manufacture Date: 2017/5/30 Num ID Code Rev 0 &HFFFF 54, 43 1 &H8325 38, 25;

    var NEWLINE = String.fromCharCode(13, 10);

    var myArray = myData.split("\n");
    for (var i = 0; i < myArray.length; i++) {
    scriptThread.sendString(myArray[i]);
    scriptThread.sendString(NEWLINE);
    }


    Is there a way I can essentially do the above, so that I do not need to do something like:

    varf myData = 'Chemistry: LiPo \
    Serial Number: 3755 \
    Manufacture Date: 2017/5/30 \
    Num ID Code Rev \
    0 &HFFFF 54, 43 \
    1 &H8325 38, 25';

    I don't want to have to do a '\' manually for every line (there could be 50+ of them).

    I know this is more of a qtscript question, but I couldn't find anything about this on google, etc. -any ideas or suggestions?

    Thanks,
    George H. (U.S.A. Massachusetts)
    05/30/2017 2:44pm ET

     
  • Anonymous

    Anonymous - 2017-05-30

    Hi Stefan,

    it looks like when I just posted my previous message, the backquote (also called grave accent) were taken out, so actually should have been:

    varf myData =[backquote here]Chemistry: LiPo Serial Number: 3755 Manufacture Date: 2017/5/30 Num ID Code Rev 0 &HFFFF 54, 43 1 &H8325 38, 25[backquote here];

    -sorry for the confusion.

    Thanks,
    George H. (U.S.A. Massachusetts)
    05/30/2017 2:56pm ET

     
  • Stefan Zieker

    Stefan Zieker - 2017-05-31

    Hi George,

    you can save your string in a text file and then read it:

    var myData =scriptFile.readFile("your path");

    In the second part of your code you replace "\n' with '\r\n" and then you send the result (is this correct?). I would do it like this:

    myData = myData.replace(/\n/gm, "\r\n");
    scriptThread.sendString(myData);

    Greetings from Germany
    Stefan

     

    Last edit: Stefan Zieker 2017-05-31
  • Anonymous

    Anonymous - 2017-05-31

    Hi Stefan,

    that's an interesting idea -I will give it a try. Thank you!

    Thanks,
    George H. (U.S.A. Massachusetts)
    05/31/2017 1:55pm ET

     

Anonymous
Anonymous

Add attachments
Cancel