A common way to read text in C #

Source: Internet
Author: User

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 #

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.