Tag Archive: string

May 03 2008

Pad Number String with Zeroes

Sometimes a numbered list is required, such as a list to populate a ListView, TreeView or one to create sequential files in a folder. One of the main problems is that such lists typically sort the items lexicographically, so that numbered items end-up in the wrong order, such as File_1, File_10, FIle_11, …, File_2, FIle_20, …

Continue reading »

Apr 01 2008

Convert ASCII Value to Character

The Asc function takes an ASCII character code and returns the character. Print Chr( 65 ) ‘ prints “A” Print Chr( 34 ) ‘ prints ” ( quote )

Apr 01 2008

Convert String to a Number

Use the CInt function to convert a string to Integer data subtype representation. Use the CDbl function to convert a string to Double data subtype representation. Use the CSng function to convert a string to Single data subtype representation. Use the CLng function to convert a string to Long data subtype representation. Use the CByte function …

Continue reading »

Apr 01 2008

Convert Number to a String

Use the CStr to convert a number into it’s string representation pi = 3.14 Print CStr( pi ) ‘ Prints “3.14”

Apr 01 2008

String Contains Substring?

Use the InStr function to determine if a string contains a sub string. Dim str   s = "AdvancedQTP" ‘ ** The following 4 lines are case-sensitive Print InStr( s, "Advanced" ) ‘ Prints 1 Print InStr( s, "QTP" ) ‘ Prints 9 Print InStr( s, "xyz" ) ‘ Prints 0 Print InStr( s, "qtp" …

Continue reading »

Apr 01 2008

Where Is ‘93′ hides?

VBScript has no built-in function where we can find all occurrences of a sub string inside a string. Only regular with expressions ( Regexp ) the task is easier. However you need to use Regexp, Matches, and Match objects. p>I am sure that many users would choose the Regexp object for this task, and maybe …

Continue reading »

Apr 01 2008

Find Last Occurrence of Substring within a String

Find the starting position of the last occurrence of a sub string within a string. ( With strings, the first character is at position 1 ) Dim s s = “QuickTest Professional quicktest professional” ‘ ** The following 4 lines are case-sensitive Print InStrRev( s, “Professional” ) ‘ Prints 11 Print InStrRev( s, “QuickTest” ) …

Continue reading »

Apr 01 2008

Determine if a String Contains a Valid Date

Use IsDate to determine if a string contains a valid date. Dim d1, d2, d3 d1 = “August 12, 2004” d2 = “12/25/2000” d3 = “Tomorrow” result = IsDate( d1 ) ‘ Returns True. result = IsDate( d2 ) ‘ Returns True. result = IsDate( d3 ) ‘ Returns False.

Apr 01 2008

Extract Substring from the Beginning of a String

Use the Left Function to extract a sub string from the beginning of a string. str1 = “1234567890” Print Left( str1, 4 )

Apr 01 2008

Get Length of String

Use the Len Function to return the length of a string. str1 = “1234567890” Print Len( str1 )

Older posts «

Fetch more items