String and Math Functions in Visual Basic .NET

In this article, I will explain you about String and Math Functions in Visual Basic .NET.
  • 5047

String Functions

In Visual Basic .NET String data type are supported by the System.String class. The String Classrepresents character strings. When we want to represent a series of characters then we use String data type. String type represents a string of unicode characters and can have up to 2 billion unicode characters. String class have many built-in functions. The String class is a sealed class you cannot inherit another class from the String class. The following code show you some String Functions:

Example:

Imports System.Console
Module Module1
 
    Sub Main()
        Dim str1 As String = "My name is Atul Chaudhary"
        Dim str2 As String
        Dim str3 As String
        Dim str4 As String
        Dim str5 As String
        Dim str6 As String
        str2 = UCase(str1)
        'converts string to uppercase
        WriteLine(str2)

        str3 = LCase(str1)
        'converts string to lowercase
        WriteLine(str3)

        str4 = str1.Substring(11, 6)
        'returns a substring
        WriteLine(str4)

        str5 = str1.Clone
        'clones a string
        WriteLine(str5)

        str6 = str1.GetHashCode
        'gets the hashcode
        WriteLine(str6)
        Read()
    End Sub
 
End Module

Output of String Functions:

Output1.gif
 

Math Functions

Visual Studio .NET provides an easy way of performing mathematical calculations. Math functions are stored in System.Math namespace. We have to import this namespace when we want to work with Math functions. Math class have built-in functions which help us calculate the addition, subtraction, multiplication, division, exponentiation, integer division, trigonometry values, square roots, logarithm values, etc. The following code show you some Math Functions:

Example:

Imports
 System.Console
Imports System.Math
Module Module1
 
    Sub Main()
        WriteLine("Tan 90 is" & " " & Tan(90))
        'display Tan90 value
        WriteLine("Square root of 121 is " & " " & Sqrt(121))
        'displays square root of 121
        WriteLine("Log value of 15 is" & " " & Log(15))
        'displays the logarithm value of 15
        Read()
    End Sub
 
End Module

Output of Math Functions: 

Output2.gif 
 

Summary

I hope this article help you to understand String and Math Functions in Visual Basic .NET.

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.