Forum Discussion

manojgovikari's avatar
manojgovikari
Contributor
14 years ago

How to Replace character "µ" with null or empty string

Hi ,

I need to replace the character "µ" with empty stirng.. i tried the following code but not successded.

1. Replace(µg/dL, "µ","")

2. Replace(µg/dL, char(181),"")



Please help me getting this resolved.

10 Replies

  • I tried with Ascci values to replace the character. But still its not working. Pls help me to solve this issue.
  • I tried with the above code. that does not workout. I think in the apllication they might have used some image or some other thing to show the special character. So is there any way to replace that. I cannot compare the application value with my input data due to this character. Even i tried pasting the sybol from apllication for replacing with null string, but it  still appeared.
  • Hi Manoj,



    Please post here a screenshot of your application with the "µ" character.

    Also, please select the object that displays the "µ" character in the Object Browser or Object Spy, take screenshots of the entire list of the object's properties and post them here.

    I'll take a look and try to figure out what could be the problem.
  • Find the attached object spy and aplication has some text area where this character is diaplsyed.  let me know how this can be replaced.
  • Hi Manoj,



    Thanks for the screenshots. I see that the "µ" character is part of the label text and also used in the label object name in tests.

    However, I'm afraid I still don't understand your scenario completely and why this character is a problem. Please clarify what you're trying to accomplish:

    - use a property checkpoint to verify the label text while ignoring the "µ" character;

    - get text from the label and then process it somehow;

    - mask this character in the object name, so you don't have to directly write it in your test -- e.g. SwingObject("<html>*</html>") instead of SwingObject("<html>4...50%...< 1.5 µg/dL...> 1.5µg/dL...baseline....</html>");

    - something else.

    It would also help if you attached here your entire test and the failed test logs demonstrating the problem. (If you don't want to post them on a public forum, you can send them privately to our Support Team using this form.)



    Thanks!
  • Thanks for helping me. Actually we need to compare the text displayed in apllication with the expected text. But "µ" is not compared with the expected text so i need to replace this with the empty string before comparison. Tried with Chr(181) and aqString.Replace options but does not workout.
  • Hi Manoj,



    How are you comparing the values? Are you using string comparison (==) or a property checkpoint (aqObject.CheckProperty)? Is the expected value hard-coded in your script, or are you reading it from an external data source? Please post here the script code you're using, so we can get a better insight into what's happening.



    I've also tried to verify text with the "µ" character in Notepad, and it works just fine for me, without replacing anything:



    Sub Test

    str = "<html>4...50%...< 1.5 µg/dL...> 1.5µg/dL...baseline....</html>"



    Set memo = Sys.Process("Notepad").Window("Notepad").Window("Edit")

    memo.SetText str



    aqObject.CheckProperty memo, "wText", cmpEquals, str

    End Sub


    Are you sure that the problem isn't caused by something else?
  • Expected result captured from External excel file and it will be compared using Instr.

    If Instr(ActualResult, Expected Result) > 0 Then

     Log PASS

    Else

     Log FAIL

    End IF



    StrComp is also not working due this character. Is there any technique to replace/remove those special characters.
  • Hi Manoj,



    VBScript's InStr and StrComp both support Unicode, so there shouldn't be any problems with Greek and Korean characters.

    I'm quite sure the problem is related to something else, for example, some extra spaces that make the difference. But without seeing your tested app, Excel file and complete script at first hand, it's just guesswork.



    If you could send your tested application, test project and Excel file to our Support Team (under an NDA if needed), they would take a closer look and pin down the exact problem.



    Otherwise there's not much I can suggest, I'm afraid.

    You could try TestComplete's case-insensitive property checkpoint instead of InStr to see if it makes a difference:





    Or you could debug your script and watch variable values to figure out how and where exactly the actual and expected values differ. For example, you can calculate character codes for each character in the expected and actual values, post them to the test log and then compare them to see if there's a difference:

    Sub Main

      ...

      Log.Message "Actual value length: " & Len(ActualResult)

      Log.Message "Actual value character codes:"

      Log.Message GetCharCodeStr(ActualResult)



      Log.Message "Expected value length: " & Len(ExpectedResult)

      Log.Message "Expected value character codes:"

      Log.Message GetCharCodeStr(ExpectedResult)

      ...

    End Sub



    Function GetCharCodeStr(Str)

      Dim i, res, chr, code

      res = ""



      For i = 1 To Len(Str)

        chr = Mid(Str, i, 1)

        code = AscW(chr) : If code < 0 Then code = code + 65536

        res = res & code & "(" & chr & ") "

      Next

      GetCharCodeStr = res

    End Function


    Good luck!