Forum Discussion

simonaferrara's avatar
simonaferrara
Frequent Contributor
2 years ago
Solved

Search for a substring using wildcards

Hi,

 

I would like to search a substring within a string that contains some values that change at runtime.

My string is, for example:

"Result Id: n=3;i=916169501"

I'm not interested to check the n and i values, but only the string format.

 

I've tried these (to simplify the example, I've directly set an input string for the comparison), by using the aqString.Find method.

 

function test()
{
//  OK --> it returns 7, so the substring is found
aqString.Find("Result: Id: n=3;i=916169501","Id: ns=3;i=916169501");


//  KO --> it returns -1, so the substring is not found
aqString.Find("Result: Id: n=3;i=916169501","Id: ns=*;i=*");

 

//  KO --> it returns -1, so the substring is not found
aqString.Find("Result: Id: n=3;i=916169501","Id: ns=?;i=*");
}

 

Probably the aqString.Find method doesn't handle wildcards, can you help me how can I reach my result?

 

Thanks

Simona

  • I post the solution found with the help of mikef , that works!

     

    Using aqString.StrMatches to compare the structure, using regex. For example : 

     

      inputString = "Result Id: n=3sdfsdf;i=9161634395asdf01"
      
      returnValue = aqString.StrMatches("Result Id: n=.*;i=.*",inputString)
      
      Log.Message(returnValue)
      

     

2 Replies

  • simonaferrara's avatar
    simonaferrara
    Frequent Contributor

    I post the solution found with the help of mikef , that works!

     

    Using aqString.StrMatches to compare the structure, using regex. For example : 

     

      inputString = "Result Id: n=3sdfsdf;i=9161634395asdf01"
      
      returnValue = aqString.StrMatches("Result Id: n=.*;i=.*",inputString)
      
      Log.Message(returnValue)
      

     

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    Is this what you are trying to validate?  That both these conditions are true

    • ID:n= exists at a specific column no matter what follows it
    • ;i= exists at a specific column no matter what follows it

     

    I would do it in two separate checks and check that they are both true

    aqString.Find(InputStringSubStringStartPositionCaseSensitive)

    something like

     

    if

    (

    (aqString.Find("Result: Id: n=3;i=916169501","Id: n",7)) <> -1

    and

    (aqString.Find("Result: Id: n=3;i=916169501",";i=",10)) <> -1

    )

    then

       do string ok stuff

    else

       do string not ok stuff