Module Module1 Sub main() Dim opt As Double Dim str,ch,n As String Do Console.WriteLine("*******program to perform string functions********") Console.WriteLine("1.convert lowercase to uppercase") Console.WriteLine("2.string extraction from left") Console.WriteLine("3.string to perform length function") Console.WriteLine("4.string to perform reverse function") Console.WriteLine("5.string to perform left trim function") Console.WriteLine("6.string to perform replace function") Console.WriteLine("7.string to perform substring function") Console.WriteLine("8.string to perform concatenation function") Console.Write("Enter your choice:") opt=Console.ReadLine() Console.Write("Enter any string:") Str=Console.ReadLine() Select Case(opt) Case 1 n=Ucase(str) Console.WriteLine("uppercase of the string is:" + n.Tostring) Case 2 Console.Write("Enter the number of characters to extract from left:") n=Console.ReadLine() Console.WriteLine(" "& n & "character(s) from the left is:" + Left(str, n)) Case 3 n=Len(str) Console.WriteLine("length of the string is:" + n.Tostring) Case 4 Console.WriteLine("Reverse of the string is:" + strReverse(str)) Case 5 Console.WriteLine("Left trim of the string is:" + LTrim(str)) Case 6 Dim Search, Replace As String Console.Write("Enter the string to be searched:") Search=Console.ReadLine() Console.Write("Enter the string to be replaced:") Replace=Console.ReadLine() n=str.Replace(Search,Replace) Console.WriteLine("String after replacement is:" + n.Tostring) Case 7 Dim x, y As Integer Console.Write("Enter the start position to extract:") x=Console.ReadLine() Console.Write("Enter the number of characters to extract:") y=Console.ReadLine() n=str.Substring(x, y) Console.WriteLine(str & "(" & x & " " & y & ")of the string is:" + n.Tostring) Case 8 Dim secstr As String Console.Write("Enter the second string to concate:") secstr=Console.ReadLine() n=String.Concat(str," ",secstr) Console.WriteLine("concatenated string is:" + n.ToString) End Select Console.Write("Do you want to continue (y/n):") ch=Console.ReadLine() Loop While (ch.Equals("y") Or ch.Equals("Y")) End Sub End Module
Write, Run & Share VB.net code online using OneCompiler's VB.net online compiler for free. It's one of the robust, feature-rich online compilers for VB.net language, running on the latest version 16. Getting started with the OneCompiler's VB.net compiler is simple and pretty fast. The editor shows sample boilerplate code when you choose language as VB.net
. OneCompiler also has reference programs, where you can look for the sample code to get started with.
OneCompiler's VB.net online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample VB.net program which takes name as input and prints hello message with your name.
Public Module Program
Public Sub Main(args() As string)
Dim name as String = Console.ReadLine() ' Reading input from STDIN
Console.WriteLine("Hello " & name) ' Writing output to STDOUT
End Sub
End Module
Visual Basic is a event driven programming language by Microsoft, first released in the year 1991.
Variable is a name given to the storage area in order to identify them in our programs.
Simple syntax of Variable declaration is as follows
Dim variableName [ As [ New ] dataType ] [ = initializer ]
variableName = value
If condition-expression Then
'code
End If
If(conditional-expression)Then
'code if the conditional-expression is true
Else
'code if the conditional-expression is false
End If
If(conditional-expression)Then
'code if the above conditional-expression is true
Else If(conditional-expression) Then
'code if the above conditional-expression is true
Else
'code if the above conditional-expression is false
End If
If(conditional-expression)Then
'code if the above conditional-expression is true
If(conditional-expression)Then
'code if the above conditional-expression is true
End If
End If
Select [ Case ] expression
[ Case expressionlist
'code ]
[ Case Else
'code ]
End Select
For counter [ As datatype ] = begin To end [ Step step ]
'code
[ Continue For ]
'code
[ Exit For ]
'code
Next [ counter ]
For Each element [ As datatype ] In group
'code
[ Continue For ]
'code
[ Exit For ]
'code
Next [ element ]
While conditional-expression
'Code
[ Continue While ]
'Code
[ Exit While ]
'Code
End While
Do { While | Until } conditional-expression
'Code
[ Continue Do ]
'Code
[ Exit Do ]
'Code
Loop
Do
'Code
[ Continue Do ]
'Code
[ Exit Do ]
'Code
Loop { While | Until } conditional-expression
Procedure is a sub-routine which contains set of statements. Usually Procedures are written when multiple calls are required to same set of statements which increases re-usuability and modularity.
Procedures are of two types.
Functions return a value when they are called.
[accessModifiers] Function functionName [(parameterList)] As returnType
'code
End Function
Sub-procedures are similar to functions but they don't return any value.
Sub ProcedureName (parameterList)
'Code
End Sub