Trim string results / select only 2 characters of a string



Trim string results / select only 2 characters of a string To trim your string results in asp.net simply follow the below examples:

Dim strString As String = "ABCDEFG"
Response.Write(strString.Substring(0, 2))
The above example would start from the beginning of the string and display two characters (AB in this case).

If you wanted to display 2 characters, but the 3rd & 4th characters, you would do the below:

Dim strString As String = "ABCDEFG"
Response.Write(strString.Substring(3, 2))
The above would display CD.

So basically, the first number is the start position and the second number is how many characters you'd like to display.


Send a link to this page via email Send a link to this page via email