Skip to content

Instantly share code, notes, and snippets.

@JamesVStone
Created June 4, 2018 20:57
Show Gist options
  • Save JamesVStone/3eeaecc4f77b9d529f687435c4267a35 to your computer and use it in GitHub Desktop.
Save JamesVStone/3eeaecc4f77b9d529f687435c4267a35 to your computer and use it in GitHub Desktop.

VB.NET 8- String Manipulation

James Stone

String Variable Type

A string consists of an array of encoded characecters

To create a string in visual basic use

Dim myString As String

To asign it a value use

MyString = "Hello Worrld!!"

Strings can also be used in logical operations

If enteredPassword = "Password123" Then

	MsgBox("Welcome admin, your instruction is my command")

String Functions

These are a few functions that you can preform to manipulate or extract data from

  • ToUpper()
  • Trim()
  • ToLower()
  • Length()
  • Contains()
  • EndsWith()
  • Insert()
  • ToCharArray()
  • Split()
  • Substring()

Triming Strings

The Trim function will remove any blank spaces from around inputed text.

Dim myCatsName As String

MyCatsName = "kitkat      "
MyCatsName = MyCatsName.Trim

When displayed the variable MyCatsName would output as

kitkat

Char

A char is a single encoded charecter

Dim faveChar As Char

favChar = 'N'

A string is just an array of chars

To find out how many chars there are in a string use

Dim myString As String = "James"

MsgBox("There are " & myString.Length & "chars in this string")

Chars

Chars is a method of the String variable type. It can be used to find the lengh of any string.

Chars is a function that can extract a charecter from a string

MyString = "It's not wise to upset a Wookiee"

OneLetter = MyString.Chars(18)

This should return the letter 'p'

String Position

If you need to know if a string conains a certain charecter

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment