Inbuilt Functions UFT

1. Left

In UFT, one can use the Left function to find out a specified number of characters from the left of a string.
Syntax: Left(String, Length) where String is the actual string and Length is the number of characters you want to find.
2. Right

Similar like Left, Right function to find out a specified number of characters from the right of a string.
Right(String, Length)

3.  Mid

In UFT, Mid function can be used to retrieve a sub-string from a main string.
Syntax: Mid(String, Start, Length(optional))
  • String is the actual string from which you want to extract a sub-string.
  • Start is the starting position from where the sub-string should be extracted.
  • Length is the length of the sub-string to be extracted. If omitted, all the characters from the Start value till the end of the main string are taken as part of the sub-string.

4. Split Function

This function splits a string using a delimiter and returns a number of sub-strings stored in an array. For example, if you want to split the string “Sourav Ghosh” using ” ” (blank space) as a delimiter, the split function would return 2 sub-strings – “Sourav” and “Ghosh”. Both these sub-strings will be stored in an array. The first sub-string in index 0 of the array and the second sub-string in index 1 of the array.

Syntax: Split(String, Delimiter(optional), Count(optional), Compare(optional))

    >>String is the text that you want to split.
    >>Delimiter is the character or string using which you want to split the main string. If omitted, the space character (” “) is taken as the delimiter.
    >>Count is the number of sub-strings that you want the function to return. The value -1 means that all the sub-strings will be returned.
    >>Compare indicates the kind of sub-strings used while evaluating sub-strings. Value 0 indicates binary comparison and value 1 indicates textual comparison.


5. InStr Function

InStr is one of the most common string manipulation functions that you would be using in UFT. InStr function helps you determine if a smaller string is present in a bigger string or not. For example, you can use this function to determine if the string “Test” (smaller string) is present in “AutomationTest” (bigger string).

If a match is found -> returns a number that represents the position at which the match is found.
If it is a number greater than 0 that means the match is found.

Syntax: InStr(Start(optional), BigString, SmallString, Compare(optional))

    >>Start is an optional argument which specifies the position from where the search should start in the BigString. If this value is not provided, the search would start from first character.
    >>BigString is the string in which you will search for the smaller string.
    >>SmallString is the string which will be searched in the bigger or main string.
    >>Compare is an optional argument which specifies the type of search. Value 0 means binary comparison and value 1 means text comparison.

6. Trim, LTrim and RTrim Functions

In UFT, Trim function can be used to remove the blank spaces from the beginning and end of a string. For example, Trim(” automation repository “) would return “automation repository”. So here, the function Trim removed all the blank spaces from the beginning and end of the string.

LTrim (can also be called Left Trim) function removes the blank spaces from the left, ie the beginning of the string. So LTrim(” automation repository “) would return “automation repository ”

You can use RTrim (also called Right Trim) function in QTP remove the blank spaces from the right side or the end of the string. RTrim(” automation repository “) would return ” automation repository”

Syntax: Trim(string), LTrim(string), RTrim(string)

7. UCase and Lcase

 In UFT this function are used to convert string into Uppercase and Lowercase respectively.


Few more functions

Till now, we have covered only those VBScript string manipulation functions that you would be using very commonly in QTP. However, there are few more function which you would be using very rarely (or maybe not at all). Below is the list of these functions and a one liner explanation of each.

InStrRev Function This function is similar to InStr function with the only difference being that it returns the position of the occurrence of a sub-string from the end of the string.

Replace Function This function can be used to replace some sub-string within a main string with some other string. For example, if you have a string like “abaacaadea”, you can use the replace function to replace the character ‘a’ (or any sub-string) with any other character or sub-string.

Space Function You can use the Space function in QTP to create a string with a given number of blank spaces. For example, var = Space(5) would return string – ” “, i.e. a string with 5 blank spaces.

String Function You can use the String function to create a repeating character string of a specified length. str = String(5, “a”) would return the string – “aaaaa”.

StrReverse Function StrReverse function in QTP can be used to create a reverse of a string. For example, str = StrReverse(“orange”) would return the string – “egnaro”.

Join Function If you have a number of sub-strings in an array, you can use the Join function to concatenate all the sub-strings from the array into a single string.

StrComp Function StrComp function can be used to compare two strings in QTP. You can choose to ignore this function because you can perform the same task of comparing the strings using comparison operators.
 
Filter Function This function returns a zero-based array containing a subset of a string array based on a specified filter criteria.









No comments:

Post a Comment