Contains |  Concat |  Empty |  IndexOf |  LastIndexOf |  Insert |  Join |  Length |  Trim |  Split |  Replace |  StartsWith |  Substring |  Char |  PadLeft |  PadRight | 

Contains

System.String.Contains

Tells you if a string Contains another string:


In this example, the value of hasIt will be TRUE:.

hasIt = str1.Contains(str2)

In this example, the value of hasIt will be FALSE:

hasIt = str1.Contains(str3)


Concat

System.String.Concat

Concatenate up to four strings:


You can concatenate two, three or four strings.

You can also concatenate the strings in a string array.


NewString = String.Concat (strArray)


Empty

System.String.Empty

This function returns an empty string.
An empty string is a zero-length string, or "".



xstr is now "".


IndexOf

System.String.IndexOf

Find the position (or IndexOf), a character or string object in a string.


The value of x will be 8.

Dim y As Integer = str1.IndexOf(str3)

The value of y will be 19.

If the searched for string is not found, the value returned is -1.
If the string being searched is empty, the value returned is 0.



LastIndexOf

System.String.LastIndexOf

Finds the last position (or IndexOf), a character or string object in a string.
This is similar to the right function in VB6.
The last position of a string will be the rightmost position.



The value of x will be 16. This is the rightmost incidence of banana.

If the searched for string is not found, the value returned is -1.
If the string being searched is empty, the value returned is 0.



Insert

System.String.Insert(start index, value)
Inserts a string within another string at a specified starting point.


NewString will contain the string "Lions and tigers and bears"

NewString = str1.Insert(28,str3)

NewString will contain the string "Lions and tigers and bears Oh My!"


Join

System.String.Join(separator, stringArray)
System.String.Join(separator, stringArray, startIndex, count)


Creates a single string from a string array.
Join also sends a string containing the Separator value for the new string.


newString will contain "Boston|Chicago|Detroit|Memphis|Denver"
Join can also specify a starting index in the array and a count of elements to extract.

newString = String.Join(sep, strArr, 2, 3)

This example will join the array starting at the second element and will extract three array elements.
The result will be "Chicago|Detroit|Memphis"



Length

System.String.Length

Find the number of characters in a string.

Dim str1 As String = "Today is Wednesday"
Dim x As Integer = str1.Length

The value of x will be 18.



Substring

System.String.Substring(start, length)

Extract characters from the starting position for the specified length.

Dim str1 As String = "Today is Wednesday"
Dim newstr as string = str1.Substring(0, 5)

This will return the string Today.
The start is 0 which is the first position.
5 characters are returned.>br/>


Dim str1 As String = "Today is Wednesday"
Dim newstr as string = str1.Substring(8, 9)

This will return the string Wednesday.



Trim / TrimStart / TrimEnd

System.String.Trim
System.String.TrimStart
System.String.TrimEnd

Trim removes whitespace from the beginning and end of a string.
TrimStart removes whitespace from the beginning of a string.
TrimEnd removes whitespace from the end of a string.


Dim str1 As String = "    Abe Lincoln    "
Dim NewString As String = str1.Trim

NewString will be "Abe Lincoln".

Dim str1 As String = "    Abe Lincoln    "
Dim NewString As String = str1.TrimStart

NewString will be "Abe Lincoln    ".

Dim str1 As String = "    Abe Lincoln    "
Dim NewString As String = str1.TrimEnd

NewString will be "   Abe Lincoln".



Split

System.String.Split

Takes a string and breaks it into a string array, based on the specified separator character.

Dim str1 As String = "Boston, Chicago, Detroit, Memphis, Denver"
Dim strArray() As String = str1.Split(",")

This example will create an array (strArray) with these elements:

strArray(0) = "Boston"
strArray(1) = "Chicago"
strArray(2) = "Detroit"
strArray(3) = "Memphis"
strArray(4) = "Denver"

The array was created by splitting the string into elements where the specified separator is found.
In this case, the designated separator character was a comma.



Replace

System.String.Replace

Replace a set of characters or a string, from another string.


The value of NewString is "Today is Thursday".


StartsWith

System.String.StartsWith(string)

Determine if a string Starts With a specified character or string.


The value of markup will be TRUE in this example.


Char

System.String.Char (index)

Get the character at the index location in the string. This uses a zero-based index.


The value of val will be H.


The value of val will be y.


The value of val will be Y.


PadLeft/PadRight

System.String.PadLeft(width)
System.String.PadLeft(width, character)
System.String.PadRight(width)
System.String.PadRight(width, character)


PadLeft right-aligns the characters in a string and pads the leftside to the specified length.

PadRight left-aligns the characters in a string and pads the rightside to the specific length.

Both PadLeft and PadRight have an optional parameter to specify the character to fill the string.

If this is not specified, the padding will be blanks.


The value of NewString is "Happy Birthday      ".


The value of NewString is "Happy Birthday"


In this example, the period character is specified.
This will create leading for a Table Of Contents.



The valueNewstring is "......Chapter.1"













Copyright © 2006-2019, LQSystems,Inc. All rights reserved.


   Printer Friendly Page