Forum Discussion

sarya's avatar
sarya
Frequent Contributor
15 years ago

String comparison methods

Hi,



I have a window for which I need to verify that the caption .the value is "Report: C:\Program Files (x86)\Report2Web Client Tools\BursterWatch\PQ5.mfd  Profile: PQ5.mfdProfile - Report2Web Burster" .

The variable "b" returns substring as 'C:\Program Files (x86)\ReportWeb2Client Tools\BursterWatch\PQ5.mfd'.I tried to use aqstring.Find,aqstring.Compare but soemhow it is not able to compare correctly as it should return true.Instead it returns false.In the below code I simply used the comparison operator but still it returns with an error .Why are these methods not working for this string . Please tell me the correct way to do it.Most of my scripts have compare string operation and all have the same problem.For some it works,for some it doesn't.


The code looks like this:


BurstWnd = Sys.Process("Burster").VBObject("frmPDFView").WndCaption;

b = aqString.SubString(BurstWnd,8,68);

if (b == 'C:\\Program Files (x86)\\ReportWeb2Client Tools\\BursterWatch\\PQ5.mfd')

Log.Message(true);

else 

Log.Error(b);



Thanks.


 



  • Hi Sumedha,





    I've observed that, after executing the following code snippet

      BurstWnd = "Report: C:\\Program Files (x86)\\Report2Web Client Tools\\BursterWatch\\PQ5.mfd  Profile: PQ5.mfdProfile - Report2Web Burster";  

      b = aqString.SubString(BurstWnd,8,68);


    the "b" variable's value is equal to "C:\Program Files (x86)\Report2Web Client Tools\BursterWatch\PQ5.mfd " (an extra space at the end) instead of "C:\Program Files (x86)\ReportWeb2Client Tools\BursterWatch\PQ5.mfd".





    In any case, as you are using JScript, I suggest that you implement the verification by using the indexOf method. Here is an example:

    function Test()

    {

      var BurstWnd = "Report: C:\\Program Files (x86)\\Report2Web Client Tools\\BursterWatch\\PQ5.mfd  Profile: PQ5.mfdProfile - Report2Web Burster";

      Log.Message(Verify(BurstWnd, "C:\\Program Files (x86)\\Report2Web Client Tools\\BursterWatch\\PQ5.mfd"));

    }





    function Verify(Str, Substr)

    {

      return (Str.indexOf(Substr) != -1) ? true : false

    }






    For additional information about the indexOf method, please see the "indexOf Method (Windows Scripting - JScript)" MSDN Library article.