Search code examples
iosinstrumentsios-ui-automation

how to get specific word out of sentence in UIAutomation?


If i need to check whether some specific word is present in some sentence, then what syntax/code i should use in javascript for UIAutomation?


Solution

  • Use function indexOf():

    Search a string for "welcome":

     var str="Hello world, welcome to the universe.";
     var n=str.indexOf("welcome"); 
    

    The result of n will be:

    13

    This method returns -1 if the value to search is not present.