Learn how to work with the string class in the .NET framework. Review how to manipulate string content, parse strings, format numeric and date types, and more.
Overview
Syllabus
Introduction
- Working with text in .NET
- How to access and clone the GitHub code
- Open the cloned solution in Visual Studio
- Work with Git branches
- .NET, text, and strings
- What is a string?
- Declaring a string variable
- Initialize a string variable
- Immutable: What does that mean in .NET strings?
- The char, the building block of a strong
- Initialize a string from a char array
- Get a char from a string
- Use char methods to analyze Unicode data
- Three ways to work with string literals
- Use escape sequences to add control chars to a string
- Use verbatim string literals
- Combine strings with String.Concat
- Combine strings with the concatenation operator
- Composite formatting with placeholders
- Use C# interpolation for simpler composite formatting
- Use StringBuilder to improve performance
- Use Perf Monitor to examine performance improvements
- Splitting strings into an array
- Use LINQ to query string array
- Joining an array into a string
- Trim unwanted content from a string
- Work with a subset of a string
- Verify that string contains search characters
- Replace and remove content
- Challenge: Better substring
- Solution: Better substring
- Custom types and string conversions
- How custom types are converted to string with toString()
- How custom types override toString()
- IFormattable and the toString() call order
- Custom formats with IFormattable
- Working with culture-specific formats
- Challenge: Split a string into two numbers
- Solution: Convert a string to the type with parse()
- Add custom filters to parse()
- Prevent exceptions with a tryParse() implementation
- Formatting data with the built-in numeric formats
- Formatting data with custom formatters
- Apply conditional string formats
- Formatting dates
- Challenge: Ordinal formatting
- Solution: Ordinal formatting
- The parse() method and the Convert class
- Use tryParse() for better error handing
- Why is culture important for strings?
- The CultureInfo class
- Use culture when formatting strings
- Invariant culture and strings
- How string comparison works in .NET
- Test for equality with String.Equals
- Compare strings with String.Compare
- Sort strings with Array.Sort and LINQ
- Next steps
Taught by
Walt Ritscher