Microsoft & .NET Visual Basic Advanced String Functions

Advanced String Functions

Last week, we looked at the basic
string functions, and some of their applications. This week, we will look at the more
advanced string functions, and put them into use.

LTrim$, RTrim$, Trim$

These are the first functions that we will look at this week. They only
just fall into the advanced category. They are used to remove preceding and trailing
spaces from strings. For example:

mystring = " Hello! "
LTrim$(mystring) contains "Hello! "
Rtrim$(mystring) contains " Hello!"
Trim$(mystring) contains "Hello!"
It is equal to LTrim$(RTrim$(mystring))

This function is particularly useful for API functions, which often return
strings with spaces preceding and trailing the string.

Syntax:

LTrim(string)
RTrim(string)
Trim(string)

Asc

This function returns the ASCII character code for a character. This is
particularly useful for something that encodes passwords: you could take 1 from the
character code, just as a simple code.

Asc("A") returns 65
Asc("A happy elephant") returns 65
(it takes the first character only)

Syntax:

Asc(string)

Format$

To explain this function in detail would need a lot more room than this
quick round up of advanced string functions allows. So, I will just touch on some of its
functionality. There is lots of information in the help file about it, so try looking
there for more in-depth information.

Format(123.4, "#####.##") returns "123.4"
Format(123.4, "00000.00") returns "00123.40"
Format(123456.789, "###,###.#") returns "123,456.7"
Format(#07:14:23#, "hh:mm AM/PM") returns "07:18 AM"

Latest Posts

Related Stories