0% found this document useful (0 votes)
3 views

string processing in VB.NET

Uploaded by

alaabuikhzam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

string processing in VB.NET

Uploaded by

alaabuikhzam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Question 1: String Manipulation with Replace

Dim str As String = "The quick brown fox jumps over the lazy dog"

Dim result As String = str.Replace("quick", "fast").Replace("dog", "cat")

Console.WriteLine(result)

Trace the output.

Expected Output: The fast brown fox jumps over the lazy cat

Question 2: Substring and IndexOf

Dim text As String = "VB.NET is a powerful language"

Dim sub As String = text.Substring(text.IndexOf("powerful"), 9)

Console.WriteLine(sub)

Trace the output.

Expected Output: powerful

Question 3: String Split with Multiple Delimiters

Dim data As String = "apple;orange,banana;grape"

Dim fruits() As String = data.Split(";,")

For Each fruit As String In fruits

Console.WriteLine(fruit)

Next

Trace the output.

Expected Output:
apple
orange
banana
grape

Question 4: String Formatting with Conditional Logic

Dim name As String = "Alice"

Dim age As Integer = 30

Dim result As String = String.Format("Name: {0}, Age: {1}, Status: {2}", name, age, If(age >= 18, "Adult", "Minor"))

Console.WriteLine(result)
Trace the output.

Expected Output: Name: Alice, Age: 30, Status: Adult

Question 5: String Comparison with IgnoreCase

Dim str1 As String = "hello"

Dim str2 As String = "HELLO"

Dim isEqual As Boolean = String.Compare(str1, str2, StringComparison.OrdinalIgnoreCase) = 0

Console.WriteLine(isEqual)

Trace the output.

Expected Output: True (case-insensitive comparison)

Question 6: StringBuilder Append and Replace

Dim sb As New System.Text.StringBuilder("Hello World!")

sb.Append(" How are you?")

sb.Replace("World", "VB.NET")

Console.WriteLine(sb.ToString())

Trace the output.

Expected Output: Hello VB.NET! How are you?

Question 7: String Length and Indexing

Dim sentence As String = "Programming in VB.NET"

Dim length As Integer = sentence.Length

Dim index As Integer = sentence.IndexOf("VB")

Console.WriteLine("Length: " & length)

Console.WriteLine("Index of 'VB': " & index)

Trace the output.

Expected Output:
Length: 22
Index of 'VB': 14

Question 8: ToUpper, ToLower with String Concatenation

Dim part1 As String = "VB"


Dim part2 As String = ".NET"

Dim result As String = part1.ToUpper() & part2.ToLower()

Console.WriteLine(result)

Trace the output.

Expected Output: VB.net

Question 9: String Trim and StringLength

Dim input As String = " Hello, World! "

Dim trimmed As String = input.Trim()

Dim length As Integer = trimmed.Length

Console.WriteLine("Trimmed: '" & trimmed & "' Length: " & length)

Trace the output.

Expected Output: Trimmed: 'Hello, World!' Length: 15

Question 10: StringBuilder with Loop

Dim sb As New System.Text.StringBuilder()

For i As Integer = 1 To 5

sb.Append("Number " & i & " ")

Next

Console.WriteLine(sb.ToString())

Trace the output.

Expected Output: Number 1 Number 2 Number 3 Number 4 Number 5

You might also like