Book Image

Mastering Unity Scripting

By : Alan Thorn
Book Image

Mastering Unity Scripting

By: Alan Thorn

Overview of this book

Table of Contents (17 chapters)
Mastering Unity Scripting
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Linq and regular expressions


Linq, of course, need not work in isolation. It can, for example, be combined with regular expressions to extract specific string patterns from a larger string that converts the matched results into a traversable array. This can be especially useful in processing comma-separated value files (CSV files), for example, where data is formatted inside a text file, each entry being separated by a comma character. Both Linq and regular expressions can be used to read each value into a unique array element very quickly and easily. For example, consider an RTS game where human names must be generated for new units. The names themselves are stored in a CSV format and are divided into two groups: male and female. On generating a character, it can be either male or female, and an appropriate name must be assigned to them from the CSV data, as shown in the following code sample 6-24:

01 //Generate female name
02 //Regular Expression Search Pattern
03 //Find all names prefixed...