There are built-in function in Visual Basic that deal with string manipulation.
These function come in especially handy when you are dealing with:
Here are some of the string manipulations functions that are built into the Visual Basic Language:
|
Function |
Description |
Example |
Return Value |
| Len( ) | Returns the length of the string | strlength=Len("Hello") | strlength = 5 |
| Val( ) | Converts a string to a numeric value | Value = Val("78") | Answer = 78 |
| Str( ) | Converts a numeric value into a string | Answer = Str(78) | Answer = "78" |
| Chr( ) | Returns character equivalent | Letter =Chr(65) | Letter = "A" |
| Asc( ) | Returns ASCII equivalent | Value = Asc("A") | Value = 65 |
| Ucase( ) | Converts to uppercase | Answer = Ucase("Hello") | Answer = HELLO |
| Lcase( ) | Converts to lowercase | Answer = Lcase("Hello") | Answer = helllo |
| Isnumeric( ) | Verifies if a value is numeric | Testit = Isnumeric(Answer) | Testit = false |
| Format( ) | Formats the given text with predefined formats | txtanswer.text = Format(1000.5,"standard") | txtanswer.text= 1,000.50 |
| Strcmp( ) | Compares two strings (true or false) | Answer = StrComp("A","a",1) | Answer = true |
| Trim( ) | Removes all leading and trailing spaces | Answer = Trim(" Hello ") | Answer = "Hello" |
| Mid(string, start[, length]) | Returns a Variant (String) containing a specified number of characters from a string | Answer = Mid("Hello",2,2) | Answer = "el" |