Tutorialspoint

String Contains String

Module strings
   Sub Main()
      Dim str1 As String
      str1 = "This is test"
      
      If (str1.Contains("test")) Then
         Console.WriteLine("The sequence 'test' was found.")
      End If
      Console.ReadLine()
   End Sub
End Module

VB.Net Nested Select Case Statement

Module decisions
   Sub Main()
      'local variable definition
      Dim a As Integer = 100
      Dim b As Integer = 200
      Select a
         Case 100
            Console.WriteLine("This is part of outer case ")
            Select Case b
               Case 200
                  Console.WriteLine("This is part of inner case ")
            End Select
         End Select
      Console.WriteLine("Exact value of a is : {0}", a)
      Console.WriteLine("Exact value of b is : {0}", b)
      Console.ReadLine()
   End Sub
End Module

VB.Net Hello World

Imports System
Module Module1
   'This program will display Hello World 
   Sub Main()
      Console.WriteLine("Hello World")
      Console.ReadKey()
   End Sub
End Module

VB.Net - Regular Expressions Example1

Imports System.Text.RegularExpressions
Module regexProg
   Sub showMatch(ByVal text As String, ByVal expr As String)
      Console.WriteLine("The Expression: " + expr)
      Dim mc As MatchCollection = Regex.Matches(text, expr)
      Dim m As Match
      For Each m In mc
          Console.WriteLine(m)
      Next m
   End Sub
   Sub Main()
      Dim str As String = "A Thousand Splendid Suns"
      Console.WriteLine("Matching words that start with 'S': ")
      showMatch(str, "\bS\S*")
      Console.ReadKey()
   End Sub
End Module

VB.Net Regex Class Example3

Imports System.Text.RegularExpressions
Module regexProg
   Sub Main()
      Dim input As String = "Hello    World   "
      Dim pattern As String = "\\s+"
      Dim replacement As String = " "
      Dim rgx As Regex = New Regex(pattern)
      Dim result As String = rgx.Replace(input, replacement)
      Console.WriteLine("Original String: {0}", input)
      Console.WriteLine("Replacement String: {0}", result)
      Console.ReadKey()
   End Sub
End Module

VB.Net Regex Class Example2

Imports System.Text.RegularExpressions
Module regexProg
   Sub showMatch(ByVal text As String, ByVal expr As String)
      Console.WriteLine("The Expression: " + expr)
      Dim mc As MatchCollection = Regex.Matches(text, expr)
      Dim m As Match
      For Each m In mc
          Console.WriteLine(m)
      Next m
   End Sub
   Sub Main()
      Dim str As String = "make a maze and manage to measure it"
      Console.WriteLine("Matching words that start with 'm' and ends with 'e': ")
      showMatch(str, "\bm\S*e\b")
      Console.ReadKey()
   End Sub
End Module

VB.Net Regex Class

Imports System.Text.RegularExpressions
Module regexProg
   Sub showMatch(ByVal text As String, ByVal expr As String)
      Console.WriteLine("The Expression: " + expr)
      Dim mc As MatchCollection = Regex.Matches(text, expr)
      Dim m As Match
      For Each m In mc
          Console.WriteLine(m)
      Next m
   End Sub
   Sub Main()
      Dim str As String = "A Thousand Splendid Suns"
      Console.WriteLine("Matching words that start with 'S': ")
      showMatch(str, "\bS\S*")
      Console.ReadKey()
   End Sub
   End Module

VB.Net BinaryWriter Class

Imports System.IO
Module fileProg
   Sub Main()
      Dim bw As BinaryWriter
      Dim br As BinaryReader
      Dim i As Integer = 25
      Dim d As Double = 3.14157
      Dim b As Boolean = True
      Dim s As String = "I am happy"
      'create the file
      Try
          bw = New BinaryWriter(New FileStream("mydata", FileMode.Create))
      Catch e As IOException
          Console.WriteLine(e.Message + "\n Cannot create file.")
          Return
      End Try
      'writing into the file
      Try
          bw.Write(i)
          bw.Write(d)
          bw.Write(b)
          bw.Write(s)
      Catch e As IOException
          Console.WriteLine(e.Message + "\n Cannot write to file.")
          Return
      End Try
      bw.Close()
      'reading from the file
      Try
          br = New BinaryReader(New FileStream("mydata", FileMode.Open))
      Catch e As IOException
          Console.WriteLine(e.Message + "\n Cannot open file.")
          Return
      End Try
      Try
           i = br.ReadInt32()
          Console.WriteLine("Integer data: {0}", i)
          d = br.ReadDouble()
          Console.WriteLine("Double data: {0}", d)
          b = br.ReadBoolean()
          Console.WriteLine("Boolean data: {0}", b)
          s = br.ReadString()
          Console.WriteLine("String data: {0}", s)
      Catch e As IOException
          Console.WriteLine(e.Message + "\n Cannot read from file.")
          Return
      End Try
      br.Close()
      Console.ReadKey()
   End Sub
End Module

VB.Net StreamWriter Class

Imports System.IO
Module fileProg
   Sub Main()
      Dim names As String() = New String() {"Zara Ali", _
         "Nuha Ali", "Amir Sohel", "M Amlan"}
      Dim s As String
      Using sw As StreamWriter = New StreamWriter("names.txt")
          For Each s In names
              sw.WriteLine(s)
          Next s
      End Using
      ' Read and show each line from the file. 
      Dim line As String
      Using sr As StreamReader = New StreamReader("names.txt")
          line = sr.ReadLine()
          While (line <> Nothing)
              Console.WriteLine(line)
              line = sr.ReadLine()
          End While
      End Using
      Console.ReadKey()
   End Sub
End Module

VB.Net FileStream Class

Imports System.IO
Module fileProg
   Sub Main()
      Dim f1 As FileStream = New FileStream("sample.txt", _
              FileMode.OpenOrCreate, FileAccess.ReadWrite)
      Dim i As Integer
      For i = 0 To 20
          f1.WriteByte(CByte(i))
      Next i
      f1.Position = 0
      For i = 0 To 20
          Console.Write("{0} ", f1.ReadByte())
      Next i
      f1.Close()
      Console.ReadKey()
   End Sub
End Module

1 2 3 4 5 6 7 8 Next
Advertisements
Loading...