QTP Mid Function

Mid Function:

The Mid function returns a specific number of characters from a strings.
QTP Mid Function
HP QTP MID Function

Note:We can Use the Len function to determine the number of characters in a string.
Syntax:
Len(string)
Ex:
str1="d3g4 g5h6j6"
strlen=len(str1)
MsgBox strlen

Which will returns total characters count in a string as str1 having 11 includng spaces.

Lets see Mid function

Syntax:
Mid(String,start,[Optional] Length)

String : The specified string from which characters are returned.
Start : The starting position of the String
Length : [Optional] The number of characters to get or return.

Example 1:

Str2 = "Hello World"
  flen=Mid(str2,1,1) 'Which will return first character from the string because starting is 1 and length is 1
print "Specific character from the string is :"&flen
Output is :Specific character from the string is :d

Another Example:Get all characters, starting at position 1

    str3="d3g4g5h6j6"
    rlen=Mid(str3,1)
print "Specific character from the string is :"&rlen
In this above example we have mentioned only starting position but not mention length means ending position
Output is :Specific character from the string is :d3g4 g5h6j6

Example 3:

How to find numerics in a string

Lets see the below example

1.Declare the string
str1="d3g4g5h6j6"
strlen=len(str1) ' Find length of the string
l_num="" 'Here we are taking this one as empty to store the strings values   
For i=1 to strlen ' Use for loop to check entire string for each characters            y=mid(str1,i,1) ' i have taken start position at 1 and length position at 1 
If ( isnumeric(y)=True) Then 'Verify if in string numerics presents in case it true then it will return
        l_num= l_num & y
 Print "l_num is" &l_num
 'In l_num it will save the numerics data with one by one as below
                End If
    Next
    Print "Numerics in Specified String is :" &l_num 'Here it will display output

Output:

l_num is :3
l_num is :34
l_num is :345
l_num is :3456
l_num is :34566
Numerics in Specified String is :34566

Conclusion:

Thank you for reading the article please provide suggestions regarding article and if anything is missing or need to add more information please feel free to post comment on this article.

Post a Comment

1 Comments

  1. I enjoy looking through a post that can make men and women think.
    Also, thanks for permitting me to comment!

    ReplyDelete