Saturday, August 29, 2020

String Functions in Visual Basic:

String functions:

LCase() function:

Return a string that has been passed to it as an augment convert it to lowercase string

LCase(String)

e.g LCase(“PRATIK”) returns “pratik”

UCase() function:

Return a string that have been passed to it as an argument converted to uppercase string

UCase(string)

e.g UCase(“pratik”) returns “PRATIK”

Len( string):

Gives the length of the string which is passed to it as an argument.

e.g Len(“Pratik”) gives 6

LTRIM( string)

Return the string without any leading spaces

e.g Print LTRIM(“  BSC  ”) gives “BSC  ”

RTRIM(string)

Return the string without any trailing spaces 

e.g Print RTRIM(“  BSC  ”) gives “  BSC”

TRIM(string)

Return string without any leading or trailing spaces.

e.g Print TRIM(“  BSC  ”) gives “BSC”

LEFT(String, length)

Return the specified number of characters from the left side of this string.

e.g Print LEFT(“Bajaj College of Science”, 5) gives “Bajaj”

RIGHT(String, length)

Return the specified number of character from the right side of the screen

e.g Print RIGHT (“Bajaj College of Science”, 7) gives “Science”

MID(String, Start,Length)

Return the specified number of characters from the specified position of the string

e.g print MID (“Bajaj College of Science”, 7, 7) gives “College”

CHR(charcode)

Return the character associated with the specified ASCII number.

e.g Print CHR(65) return “A”

ASC(String)

Return the ASCII number for the first letter in the string.

e.g Print ASC(“A”) return 65 

InStr() Function

It is used to find the occurrence of the one string inside other string along with the position of it.

Return a Long value specifying the position of the first occurrence of the one string in another.

Syntax:

InStr(String1, String2)

e,g print Instr(“Pratik” , “a”)  return 2 which is the position of string “a” in the string  Pratik.

StrComp() Function:

Return a(Variant) integer indicating the result of the string comparison.

e.g  StrComp(String1, String2)

Function returns an integer value depending on the result of the comparison as follows

String1 is less than string2

-1

String 1 is equal to string 2

0

String 1 greater than string 2

1

Sting 1 or string to is Null

Null

While comparing the two string the ASCII values of the character in it are compared

e.g      StrComp(“Pratik”, “pratik”) gives  -1

StrComp(“Pratik”, “Pratik”) gives  0

StrComp(“Prashant”, “Pratik”) gives 1  


No comments:

Post a Comment