Having problems with your account or logging in?
A lot of changes are happening in the community right now. Some may affect you. READ MORE HERE

Returning string from WPFTextBox has greater character length than the input string

Returning string from WPFTextBox has greater character length than the input string

When using TypeKeys to enter a string which consists of key commands such as '<enter>' or '<tab>' into a WPFTextBox, the WPF control will add additional hidden characters.

For example, the string:

STRING sNote = "GIS Display - 'Test GIS Display ALL Layers'   -- <enter>--  Not sure how much to add <enter><tab>here for <enter><tab>this note?"

;should look like the below once entered.

In Silk Test Classic, if you use the StrTran() function against sNote to remove the <enter> and <tab> commands, the length of the string would be '97'. 

If you then return the text from the WPFTextBox to a string e.g. sReturn, it will have a length of '105'. This is the same whether you manually input the string or automate it via Silk Test.

As each character has an associated ASCII value, you can then evaluate the ASCII representation of the string's characters to determine if there are any hidden characters causing this.

To identify the ASCII values, you can use the below code which will print each character of the string along with their associated ASCII value. 

[ ] //Print the ASCII values of sReturn (the text from the control)
[ ] String charAt
[ ] int iLen = Len(sReturn)
[ ] int i = 1
[-] for i = 1 to iLen
[ ] charAt = SubStr(sReturn, i, 1)
[ ] Print("{charAt}:{Asc(charAt)}")

Below is an example of a section of the output within Silk Test Classic.

[ ] L:76
[ ] a:97
[ ] y:121
[ ] e:101
[ ] r:114
[ ] s:115
[ ] ':39
[ ] :32
[ ] :32
[ ] :32
[ ] -:45
[ ] -:45
[ ] :32
[ ] :13
[ ]
[ ] :10
[ ] -:45
[ ] -:45
[ ] :32
[ ] :32
[ ] N:78
[ ] o:111
[ ] t:116
[ ] :32
[ ] s:115
[ ] u:117
[ ] r:114
[ ] e:101

From this we can see that when <enter> is performed, it is represented using two hidden characters ":13" (enter) and ":10" (new line). Each <enter> has two characters.

When <tab> is performed, we can see that the ASCII value is ":9".

As we have three <enter> and two <tab> commands, this adds up to a total of 8 characters which is difference between sNote and sReturn strings. As a result, this will then cause the two strings to fail during any verification in Silk Test.

To resolve this issue, you can perform StrTran() against sReturn to remove the additional characters. 

[ ] //Strip the additional character and line returns for enter,new line and tab
[ ] INT iEnter = 13
[ ] INT iLine = 10
[ ] INT iTab = 9
[ ] STRING sEnter = Chr(iEnter)
[ ] STRING sLine = Chr(iLine)
[ ] STRING sTab = Chr(iTab)
[ ] sReturn = StrTran(sReturn, sEnter, "")
[ ] sReturn = StrTran(sReturn, sLine, "")
[ ] sReturn = StrTran(sReturn, sTab, "")

After performing this, the length of sNote and sReturn match and any verification should pass successfully. 

DISCLAIMER:

Some content on Community Tips & Information pages is not officially supported by Micro Focus. Please refer to our Terms of Use for more detail.
Top Contributors
Version history
Revision #:
1 of 1
Last update:
‎2017-04-10 18:39
Updated by:
 
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.