Strings and regular expressions
Working with text data is critical and for many reasons. If you need to display subtitles, show in-game text, and implement localization functionality (supporting multiple languages), then you would be working with text, specifically with Text Assets. In Unity, Text Assets refer to any text files included in the Unity project, and each asset is treated as one long string even when multiple lines are involved (each line is separated by a \n
escape character). Once your code is presented with a string like this, however, there're typically many ways in which you'll want to process it. Let's see some common but important string operations.
Null, empty strings, and white space
When processing strings, you can't always guarantee validity; sometimes, strings are badly formed and don't make sense. For this reason, you'll frequently need to validate them before processing. A common way to validate them initially is to see whether a string is null, and then (if not null...