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
Trimdrops the padding;ToUpperandReplacereturn new strings.ContainsandStartsWithanswer True or False directly.Split(","c)cuts at a Char literal — note thecsuffix.String.Joinglues the pieces back with any separator.
Keywords and builtins used here
DimEachForNextString
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.
Step 2 of 3 in Variables & strings, step 2 of 29 in Language basics.