Author Topic: LiquidUI: search_option function  (Read 6744 times)

chirag.amin@guixt.com

  • GuiXT Forum
  • Newbie
  • *
  • Posts: 34
    • View Profile
LiquidUI: search_option function
« on: July 05, 2016, 11:50:41 AM »
The search_option function takes two strings; the first is the string you want to search in and the second is the word you want to search for. The function returns the next word after the word you searched for. If the word you are searching for is not in the original string, then it returns a blank string. This is very useful for scenarios like extracting an order number from a successful saving message.



// Sample success message
z_message = "Order 124321 was saved."
// order_num will hold the value of 124321, searching for "Order" in z_message
order_num = search_option(z_message,"Order");
// Print out the message to the screen
message("Order Number:"+order_num);

// It will return the next word after the searching word
// It will return an empty string if not found
function search_option(str1, search){
   var arr = str1.split(" ");
   for (var i = 0; i<arr.length; i++){
      if(arr == search){
         if(i+1 != arr.length){
            return arr[i+1];
         }
      }
   }
   return "";
}




see attachments...
« Last Edit: June 12, 2017, 03:37:41 PM by Benjamin Dasari »