QA Focus

Jul 22 2008   4:17AM GMT

function junction: strings ‘n’ things

Sentinel627 Greg Annen Profile: Sentinel627


VBScript, the internal language of HP QuickTest Pro, is rather handy for manipulating text strings. This is especially useful when you are trying to verify a test step where only part of your actual data will match your expected data, or vice versa.

Here is a simple function which removes the specified leading characters from a text string:

function 1

Let’s say your application returns some data that always begins with “ABC” and ends in some varying values, like “ABC0089”, “ABC00390”, etc., while your expected values are extracted from a table that does not contain the constant leading value of “ABC”. You could do a quick comparison using the above function:
” If removePrefix(ApplicationDataString,”ABC”)= ExpectedString Then…”, and so on.

Here’s a similar function that can remove the trailing characters from a string:

function 2

The idea is very similar to the first function, but the target characters now appear at the end of the input string rather than at the beginning.

Finally, here is a function that can pad a string with any characters you specify, either on the right or the left side of the original text:

function 3

This technique can be used to pad number fields with zeroes at either end of the original string. For example, if you have a numeric value “12345” which must be eight characters long padded with leading zeroes, the function makes the conversion a simple call:
ApplicationData = padString(ApplicationData,8,”0″,”L”)

See, pretty easy, huh? Be creative, code wisely, and AUTOMATE!

 Comment on this Post

There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

Share this item with your network: