Module StringFunctions Sub main() Dim strng As String Dim key, nu, ascii As String key = 89 While key = 89 Or key = 121 Console.Clear() Console.WriteLine("---------------------") Console.WriteLine("---String Function---") Console.WriteLine("---------------------") Console.WriteLine("1.Asc()") Console.WriteLine("2.Chr()") Console.WriteLine("3.GetChar") Console.WriteLine("4.Instr()") Console.WriteLine("5.InStrRev") Console.WriteLine("6.LCase") Console.WriteLine("7.Left()") Console.WriteLine("8.LTrim") Console.WriteLine("9.Mid()") Console.WriteLine("10.Replace()") Console.WriteLine("11.Right()") Console.WriteLine("12.Rtrim()") Console.WriteLine("13.Str()") Console.WriteLine("14.Space()") Console.WriteLine("15.StrComp()") Console.WriteLine("16.StrRev()") Console.WriteLine("17.Trim()") Console.WriteLine("18.Ucase()") Dim x As Integer Console.WriteLine() Console.Write("Please enter your choice: ") x = CInt(Console.ReadLine()) Console.WriteLine() If x <= 18 Then Select Case x Case 1 Console.Write("Enter a String: ") strng = Console.ReadLine() Dim Ascii_val As String Ascii_val = Asc(strng) Console.WriteLine("Ascii value=" + Ascii_val.ToString()) Console.WriteLine() Case 2 Dim n As Integer Console.Write("Enter the ascii value: ") n = CInt(Console.ReadLine()) Dim char_code As String char_code = Chr(n) Console.WriteLine("char code=" & char_code) Console.WriteLine() Case 3 Console.Write("Enter a String: ") strng = Console.ReadLine() Dim get_char As String Dim n1 As Integer Console.Write("Enter the position: ") n1 = CInt(Console.ReadLine()) get_char = GetChar(strng, n1) Console.WriteLine("get char=" & get_char) Console.WriteLine() Case 4 Console.Write("Enter a String: ") strng = Console.ReadLine() Dim sub_str As String Console.Write("Enter the sub string: ") sub_str = Console.ReadLine() Dim pos As Integer = InStr(strng, sub_str) Console.WriteLine("Starting positon=" & pos) Console.WriteLine() Case 5 Console.Write("Enter a String: ") strng = Console.ReadLine() Dim sub_str2 As String Console.Write("Enter the sub string: ") sub_str2 = Console.ReadLine() Dim pos2 As Integer = InStrRev(strng, sub_str2) Console.WriteLine("Starting positon=" & pos2) Console.WriteLine() Case 6 Console.Write("Enter a String in UPPER CASE: ") strng = Console.ReadLine() Dim low_case As String = LCase(strng) Console.WriteLine("string in lower case=" & low_case) Console.WriteLine() Case 7 Console.Write("Enter a String: ") strng = Console.ReadLine() Dim n4 As Integer Console.Write("Enter number of characters: ") n4 = CInt(Console.ReadLine()) Dim sub_str4 As String = Left(strng, n4) Console.WriteLine("Sub String: " + sub_str4) Console.WriteLine() Case 8 Console.Write("Enter a String starting with spaces: ") strng = Console.ReadLine() Dim left_trim As String = LTrim(strng) Console.WriteLine("After left Trimming=" & left_trim) Console.WriteLine() Case 9 Console.Write("Enter a String: ") strng = Console.ReadLine() Dim n2, n3 As Integer Console.Write("Enter starting position: ") n2 = CInt(Console.ReadLine()) Console.Write("Enter number of characters: ") n3 = CInt(Console.ReadLine()) Dim sub_str3 As String = Mid(strng, n2, n3) Console.WriteLine("Sub String: " & sub_str3) Console.WriteLine() Case 10 Console.Write("Enter a String: ") strng = Console.ReadLine() Dim c As String Console.Write("enter character: ") c = Console.ReadLine() Dim sub_str5 As String Console.Write("enter new string: ") sub_str5 = Console.ReadLine() Dim new_str As String = Replace(strng, c, sub_str5) Console.WriteLine("New String: " + new_str) Console.WriteLine() Case 11 Console.Write("Enter a String: ") strng = Console.ReadLine() Dim n4 As Integer Console.Write("Enter starting position: ") n4 = CInt(Console.ReadLine()) Dim sub_str4 As String = Right(strng, n4) Console.WriteLine("Sub String: " + sub_str4) Console.WriteLine() Case 12 Console.Write("Enter a String with spaces at end: ") strng = Console.ReadLine() Dim right_trim As String = RTrim(strng) Console.WriteLine("After right Trimming=" & right_trim) Console.WriteLine() Case 13 Dim n As Integer Console.Write("Enter your number: ") n = CInt(Console.ReadLine()) Dim sub_str As String = Str(n) Console.WriteLine("String equivalent: " + sub_str) Console.WriteLine() Case 14 Console.Write("Enter a String: ") strng = Console.ReadLine() Dim n As Integer Console.Write("Enter number of spaces: ") n = CInt(Console.ReadLine()) Dim new_str As String = (strng & Space(n) & strng) Console.WriteLine("new_str: " + new_str) Console.WriteLine() Case 15 Console.Write("Enter 1st String: ") strng = Console.ReadLine() Dim new_str As String Console.Write("Enter 2nd String to compare: ") new_str = Console.ReadLine() Dim comp As String = StrComp(strng, new_str) If comp = 0 Then Console.WriteLine("Both strings are equal.") ElseIf comp = 1 Then Console.WriteLine("First string has greater value.") Else Console.WriteLine("Second string has greater value.") End If Console.WriteLine() Case 16 Console.Write("Enter a String: ") strng = Console.ReadLine() Dim str_rev As String = StrReverse(strng) Console.WriteLine("String in reverse: " + str_rev) Console.WriteLine() Case 17 Console.Write("Enter a String with spaces on both sides: ") strng = Console.ReadLine() Dim trimming As String = Trim(strng) Console.WriteLine("After Trimming=" & trimming) Console.WriteLine() Case 18 Console.Write("Enter a String in lower case: ") strng = Console.ReadLine() Dim up_case As String = UCase(strng) Console.WriteLine("string in UPPER case=" & up_case) Console.WriteLine() End Select Else Console.WriteLine("Invalid Number") Console.WriteLine() End If Console.Write("Do you want to continue(Y/N): ") nu = Console.ReadLine() ascii = Asc(nu) key = ascii End While End Sub End Module
Visual Basic dot net VB.net programming microsoft .net framework object oriented language network enabled technology visual basic 2005 IDE integrated development environment console application microsoft cre common runtime environment
A short Project on All String Function
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment