Extract values from strings without delimeters?
Question ID: 105974
0
0

I’m using UFT 12.01.

I have an innertext property value of a bunch of values in a list, but they don’t have a delimeter like a comma or anything to work with. Is there any way I can extract these values without a commma delimeter?

I’m pulling it from a GetROProperty and storing it in a variable like this (not real data, of course)

innertext= "AbCdEfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz"

Marked as spam
Posted by (Questions: 227, Answers: 22)
Asked on March 16, 2015 1:52 pm
140 views
Answers (2)
1
Private answer

It is possible that it is using an invisible carriage return or a line feed as a delimeter. You can try the following, as illustrated by the code examples:

*****************************************************************************************************************

innertext= ''AbCdEfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz''
text_array = Split (innertext, vbLf) 'Use line feed character as delimeter
text_array = Split (innertext, vbCr) 'Use carriage return character as delimeter
text_array = Split (innertext, vbCrLf) 'Use both carraige return and line feed character as delimeter

-----------------------------------------------------------------------------------------------------

Can you check with your development team to see how they are separating the list values behind the scenes? Would they be able to provide you with a delimeter value? Unfortunately, VBScript isn't very robust and the Split function would require a delimeter of some sort. If you had a fixed character length for each value, you could also do a Mid and extract a set of characters by position out of the total string and store into an array, such as something similar in the below code example:

-----------------------------------------------------------------------------------------------------------

strLength = Len (innertext) 'Get the total length of string for boundary

strPosition = 0

Dim str_array(10) 'initialize for 10 elements of the array (or however many will be needed)

array_elem = 0 'starting array element value

Do until strPosition >= strLength 'Create loop based on the position of the character extraction and terminate at end of string

str_array(array_elem) = Mid (innertext, strPosition, 10 ) 'grab the next 10 characters in the string at the strPosition value and store in sequential array element

strPosition = strPosition + 10

array_elem = array_elem + 1

Loop

Marked as spam
Posted by (Questions: 2, Answers: 477)
Answered on March 16, 2015 2:05 pm
0
Private answer

Looking at your innertext pattern, I am just assuming

1. the items in your list start with and uppercase character
2. each item is only one word

the following code might work if the above assumptions are true. (It can be modified for different patterns)

Dim RegEx
Set RegEx = New RegExp
Dim s
s = ''AbCdEfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz''
Dim matches

With RegEx
.Pattern = ''[A-Z][a-z]*''
.IgnoreCase = False
.Global = True
End With

Set matches = RegEx.Execute(s)

For Each match In matches
newString = newString + match + '', ''
Next

MsgBox newString

Marked as spam
Posted by (Questions: 0, Answers: 2)
Answered on March 17, 2015 9:59 pm
EyeOnTesting

Welcome back to "EyeOnTesting" brought to you by Orasi Software, Inc.

X
Scroll to Top