为了完成一项课程项目,我需要将一个文本文件加载到一个链表中。 目前为止,我能够从文件中读取数据,但是我无法将其分成部分以便将其放入链表中。
例如,我希望在空行处将这些项拆分开来: David Hunter No1 Admin
John Smith No11 Sales
Jane Appleby No5 Accounts
我尝试了String [] people = record.Split('\ n'); 但是这只是在每一行处拆分它。
我还尝试过: String [] people = record.Split('\ n \ r'); String [] people = record.Split('\ r \ n'); String [] people = record.Split('\ n \ n'); 但是由于“字符文字中的字符太多”,它无法编译。
请问有没有人能建议一种方法来完成这个任务(最好不使用正则表达式)?
例如,我希望在空行处将这些项拆分开来: David Hunter No1 Admin
John Smith No11 Sales
Jane Appleby No5 Accounts
我尝试了String [] people = record.Split('\ n'); 但是这只是在每一行处拆分它。
我还尝试过: String [] people = record.Split('\ n \ r'); String [] people = record.Split('\ r \ n'); String [] people = record.Split('\ n \ n'); 但是由于“字符文字中的字符太多”,它无法编译。
请问有没有人能建议一种方法来完成这个任务(最好不使用正则表达式)?
"\r\n\r\n"
处分割 - 注意要用双引号表示字符串而非单引号表示字符。 - Blorgbeardtxt.Split(new string[] { Environment.NewLine + Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries)
- Sky Fang