typestar

String methods in Visual Basic

Trim, Replace, Split and friends on an ordinary sentence.

Dim motto = "  make it work, make it right  "
Dim clean = motto.Trim()

Console.WriteLine(clean.ToUpper())
Console.WriteLine(clean.Replace("work", "compile"))
Console.WriteLine(clean.Contains("right"))
Console.WriteLine(clean.StartsWith("make"))

Dim halves = clean.Split(","c)
For Each part In halves
    Console.WriteLine(part.Trim())
Next
Console.WriteLine(String.Join(" / ", halves))

How it works

  1. Trim drops the padding; ToUpper and Replace return new strings.
  2. Contains and StartsWith answer True or False directly.
  3. Split(","c) cuts at a Char literal — note the c suffix.
  4. String.Join glues the pieces back with any separator.

Keywords and builtins used here

The run, in numbers

Lines
13
Characters to type
383
Tokens
109
Three-star pace
90 tpm

At the three-star pace of 90 tokens a minute, this run takes about 73 seconds.

Type this snippet

Step 2 of 3 in Variables & strings, step 2 of 29 in Language basics.

← Previous Next →

String methods in other languages