Forum Discussion

meenakshiyadav1's avatar
meenakshiyadav1
Contributor
6 years ago
Solved

How to remove unwanted "/" from a string

I  am using FullName property of a label object and then splitting the string to get the Full Name of Dynamic parent. 

This FullName Property returning the string as :"Mobile.Device(\"iPad\").Process(\"iA360 StageTest\").Window(0).TableView(0).TableViewCell(0, 2). Label(\"Gallo PICO\", 0)".

I am unable to remove "\" from the string using replace method or split method of javascript.Aways getting syntax error because of "\'. Can some guide me how can I remove "\" from the above string and get below string

"Mobile.Device("iPad").Process("iA360 StageTest").Window(0).TableView(0).TableViewCell(0, 2). Label("Gallo PICO", 0)".

 

Thanks in advance.

12 Replies

    • meenakshiyadav1's avatar
      meenakshiyadav1
      Contributor

       Thanks for the quick reponse. The main issue I am facing is that I need to replace single backslash "\" with "".  eg. "Mobile.Device(\"iPad\") should be Mobile.Device("iPad").

      It seems Testcomplete is using this "\" just before " to make it litteral ". I need this single backslash to be removed. Below is my code:

      var FName =Object.FullName   //  Results :"Mobile.Device(\"iPad\").Process(\"iA360 StageTest\").Window(0).TableView(0).TableViewCell(0, 3).Label(\"Gallo PICO\")"
      var str = FName.split("\","")  ///This give error " Invalid or Unexpected token" 

       

       If I do ..var str = FName.split("\/g","")  // This does not do anything i get a blank string.

      • Wamboo's avatar
        Wamboo
        Community Hero

        Alright, try this one:

         

        var t = a.split('"').join("''");

        :smileylol:

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    If you have the child object... why do you need the full string to find the parent?  There should be a property on the child object called "Parent" which will take you directly there.

    • meenakshiyadav1's avatar
      meenakshiyadav1
      Contributor

      tristaanogre I am finding the child object using Find All children method applied to a grand Parent object as the parent is dynamic . When I try to access the Parent property of this child objects it does not return the Parent instead it returns the grand Parent to me, maybe because I am finding the object using grandparent. 

       

      Wamboo I am confused as to how to use your suggestion. Can you please give me a bit more elaborative example. I need to remove \ .

      • Wamboo's avatar
        Wamboo
        Community Hero

        Hi,

         

        To help you better I need to know what do You want to do after formatting this string?

         

        What will be your next step?

         

        If you .split('"') and .join(' ') You will get the same result because this sign /" is again because it means "escape of the special characters in the string.