4/26/11

[VB.NET][TUT] STRINGS - Big TUT Collection Part 3

-------How to VB.NET String.Equals()

VB.NET String Equals function is to check the specified two String Object values are same or not

System.String.Equals(String str1, String str2) As Boolean

Parameters:

String str1 : The String argument

String str2 : The String argument

Returns:

Boolean : Yes/No

It return the values of the two String Objects are same

For ex :

Str1 = "Equals()"

Str2 = "Equals()"

String.Equals(Str1,Str2) returns True

String.Equals(Str1.ToLower,Str2) returns False

Because the String Objects values are different

Example:

 Public Class Form1  
   Private Sub Button1_Click(ByVal sender As System.Object, _  
   ByVal e As System.EventArgs) Handles Button1.Click  
     Dim str1 As String = "Equals"  
     Dim str2 As String = "Equals"  
     If String.Equals(str1, str2) Then  
       MsgBox("Strings are Equal() ")  
     Else  
       MsgBox("Strings are not Equal() ")  
     End If  
   End Sub  
 End Class  


-------How to VB.NET String.CopyTo()

VB.NET String CopyTo method Copies a specified number of characters from a specified position in this instance to a specified position in an array of characters.

System.String.CopyTo(ByVal sourceIndex As Integer, ByVal destination() As Char, ByVal destinationIndex As Integer, ByVal count As Integer)

Parameters:

Integer sourceIndex : The starting position of the source String

Char destination() : The character Array

Integer destinationIndex : Array element in the destination

Integer count : The number of characters to destination

Exceptions:

System.ArgumentNullException : If the destination is null

System.ArgumentOutOfRangeException :

Source Index, DestinationIndes or Count is a -ve value

Count is greater than the length of the substring from startIndex to the end of this instance

count is greater than the length of the subarray from destinationIndex to the end of destination

Example:

 Public Class Form1  
   Private Sub Button1_Click(ByVal sender As System.Object, _  
   ByVal e As System.EventArgs) Handles Button1.Click  
     Dim str1 As String = "CopyTo() sample"  
     Dim chrs(5) As Char  
     str1.CopyTo(0, chrs, 0, 6)  
     MsgBox(chrs(0) + chrs(1) + chrs(2) + chrs(3) + chrs(4) + chrs(5))  
   End Sub  
 End Class  

No comments: