Thursday, January 31, 2019

VBA - Strings

VBA - Strings


Strings are a sequence of characters, which can consist of either alphabets, numbers, special characters, or all of them. A variable is said to be a string if it is enclosed within double quotes " ".

Syntax

variablename = "string"

Examples

str1 = "string"   ' Only Alphabets
str2 = "132.45"   ' Only Numbers
str3 = "!@#$;*"  ' Only Special Characters
Str4 = "Asc23@#"  ' Has all the above

String Functions

There are predefined VBA String functions, which help the developers to work with the strings very effectively. Following are String methods that are supported in VBA. Please click on each one of the methods to know in detail.
S.No.Function Name & Description
1InStr
Returns the first occurrence of the specified substring. Search happens from the left to the right.
2InstrRev
Returns the first occurrence of the specified substring. Search happens from the right to the left.
3Lcase
Returns the lower case of the specified string.
4Ucase
Returns the upper case of the specified string.
5Left
Returns a specific number of characters from the left side of the string.
6Right
Returns a specific number of characters from the right side of the string.
7Mid
Returns a specific number of characters from a string based on the specified parameters.
8Ltrim
Returns a string after removing the spaces on the left side of the specified string.
9Rtrim
Returns a string after removing the spaces on the right side of the specified string.
10Trim
Returns a string value after removing both the leading and the trailing blank spaces.
11Len
Returns the length of the given string.
12Replace
Returns a string after replacing a string with another string.
13Space
Fills a string with the specified number of spaces.
14StrComp
Returns an integer value after comparing the two specified strings.
15String
Returns a string with a specified character for specified number of times.
16StrReverse
Returns a string after reversing the sequence of the characters of the given string.

No comments:

Post a Comment

No String Argument Constructor/Factory Method to Deserialize From String Value

  In this short article, we will cover in-depth the   JsonMappingException: no String-argument constructor/factory method to deserialize fro...