Friday, 28 June 2013

String Functions VB.NET

1. Len Function :- The Len function returns the length of the string variable given as argument to
Len Function. It counts the number of characters a string variable contains and it also counts the white spaces included in the string .
Syntax :- 
Len ( String_Variable )

Example :-

Dim Str as String  = "Hello geeks"
Dim length as integer
length = Len ( Str )
Msgbox (length )

2. Left, Right, Mid Functions :- 
* The Left Function returns specified number of characters from left side of string variable value
* The Right Function returns specified number of characters from Right side of string variable value
* The Mid Function Returns specified number of characters from anywhere in the string variable value. You have to specify from which character position to start and how much characters to take from string.

Syntax :- 
Left ( String_Variable )
Right ( String_Variable )
Mid ( String_Variable )

Example :-

Dim Str as String  = "Hello geeks"
Msgbox ( Left ( Str ))
Msgbox (Right ( Str ))
Msgbox (Mid ( Str , 3, 6 ))

3. LCase And  Ucase  :- The LCase converts a string to all lowercase and UCase Converts a String to all UpperCase Letters.

Syntax :- 
LCase ( String_Variable )
UCase ( String_Variable )

Example :- 

Dim Str as String  = "Hello geeks"
Msgbox ( LCase ( String_Variable ))
Msgbox (UCase ( String_Variable ))

4. Space Functions :- The Space Function is used to put given number of spces within string variable or between two or more string variable values .

Syntax :- 
Space ( value )

Here value specifies the number of spaces you want to put .

Example :- 

Dim Str as String  = "Hello"
Dim Str1 as String = "geeks"
Msgbox ( Str & space ( 1 ) & Str1 )
' It Returns "Hello geeks"

5. String Function :- The String Function Returns a repeating character string of Specified length The specified character will be repeated specified n number of times.

Syntax :- 
String ( n, character )

Example :-

Dim Str as String  = "Hello"
Dim Str1 as String = "geeks"
Msgbox ( String ( 4, "*" ) & Str &  String ( 1, "*" ) & Str1 & String ( 4, "*" ))
' It Returns ****Hello*geeks****

6. Instr Function :- The Instr Function is used to find a Substring within a string variable. This function uses three arguments .first is - starting position in string ,second is name of the string variable , third is Substring that is to be found within the string variable

Syntax :- 
Instr ( starting-position, var-name, Substring )

Example 

Dim Str as String = "Hello geeks"
Dim Substring as String ="gee"
Msgbox ( Instr( 0, Str, Substring ))
' It Returns 9

7. StrReverse Function :- The String Reverse Function returns a string in which the character  order will be reversed as that of order of original given string. It means in string reverse first character of original given string will be placed at last of new string after Reverse operation 

Syntax :- 
StrReverse ( String_variable )

Example :-

Dim Str as String 
Dim Reverse as String
Str = "Hello geeks"
Reverse = StrReverse ( Str )
Msgbox ( "String After Reverse is :- " + Reverse )


No comments:

Post a Comment