Personally think this code readability is not very good, because I took so long to look still very uncomfortable ~! But the practical is very practical, recorded, after the need to take away directly ~
PS: Traverse the number of rows to read the corresponding value, traverse the value to +1, because the traversal by default starts from the table header, and the real value is starting from the second row, +1 that is, from the second row began to traverse
Using unityengine;using system.collections;using System.collections.generic;public class Loadtext:monobehaviour { public string dataname;string[][] array;string [] allitems;void descdatainit () {// The content of 1 to 4 steps is to copy the text completely and make it data can be arbitrarily read textasset allitemdatabase = resources.load ("text/" +dataname, typeof ( Textasset) as TEXTASSET;//1. read file AllItems = AllItemDataBase.text.Split ("\ r" [0]);//2. Reads the contents of each row array = new string [ AllItems. length][];//3. A two-dimensional array of rows and columns: The total number of lines of text and the empty for (int i =0;i < AllItems. Length; i++) {//4. Iterate through all text, storing the contents of each row with a comma delimiter array[i] = allitems[i]. Split ("," [0]);}} String Getdatabyidandname (String Strname,int nId) { if (array.length <= 0) return ""; int nrow = Array.Length; int ncol = array[0]. Length; for (int i = 0; i < Nrow; i++) {//Line if (i = nId) {for (int j = 0; J < Ncol; J + +) {//Column if (array[0][j] = = StrN AME) { return array[i][j]; }}} Return ""; }}
A common way to read text in C #