Facility Control

 View Only
  • 1.  Extracting Values from Strings

    Posted 01-27-2018 20:05
    Hey Guys,

    I am working on a DashBoard panel to control my LED processors. One function I am working on is to control brightness based on temperature and humidity. I can send a TCP command to the LED processor and get a response from the sensors that looks like this: psen 1,1,1,344,2055,8156,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 The values I need are 344,2055,8156. The problem is that all three values are variables that could have a between 1-5 digits. So a simple substring will not work because I won't know exactly how many characters long the value will be. Is there a way to extract those three values (separately) in DB without using an external library?

    Thanks for the help!


  • 2.  RE: Extracting Values from Strings

    Posted 01-28-2018 11:34

    Could you do a split?

    var ledResponse = "psen 1,1,1,344,2055,8156,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1";
    var ledResponseArray = ledResponse.split(",",6); // ignore rest of string after 6 entries
    
    var value1 = ledResponseArray[3];
    var value2 = ledResponseArray[4];
    var value3 = ledResponseArray[5];
    

    #DashBoard


  • 3.  RE: Extracting Values from Strings

    Posted 01-28-2018 13:53
    Hey Joesph, that worked great and was much simpler than what I was attempting. Thanks for the quick response!
    #DashBoard


  • 4.  RE: Extracting Values from Strings

    Posted 01-28-2018 14:05
    Great! You're welcome!
    #DashBoard