String methods in C#
The everyday string toolkit: trim, transform, search and slice.
var raw = " The quick brown fox ";
var text = raw.Trim();
Console.WriteLine(text.ToUpper());
Console.WriteLine(text.Replace("quick", "sly"));
Console.WriteLine(text.Contains("fox"));
Console.WriteLine(text.StartsWith("The"));
Console.WriteLine(text.Substring(4, 5));
Console.WriteLine(text.Length);
How it works
Trimstrips the whitespace both ends carried in.ToUpper,Replace,ContainsandStartsWithcover most daily work.Substring(4, 5)slices by start and length;Lengthcounts characters.
Keywords and builtins used here
var
The run, in numbers
- Lines
- 9
- Characters to type
- 301
- Tokens
- 86
- Three-star pace
- 105 tpm
At the three-star pace of 105 tokens a minute, this run takes about 49 seconds.
Step 2 of 4 in Strings, step 5 of 29 in Language basics.