从文件中读取字符串数组并在datagrid中显示 [英] Reading string array from file and displaying in datagrid

查看:85
本文介绍了从文件中读取字符串数组并在datagrid中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我在文件中有字符串数组,必须读取它并在wpf中将其显示在datagrid中.

文本文件具有数组变量,如
{{name},{name2},{name3}}
{{tom},{John},{Harry}}

我尝试了以下操作,但是它没有用,因为它期望使用常规的txt文件而不是数组
string [] str = File.ReadAllLines("filepath");

就我而言,我必须从文件中读取数组,而不是简单的文本
如何做到最好?

谢谢

Hello I have string arrays in a file that have to read it and display in the datagrid in wpf.

The text file has array vaues like
{{name}, {name2}, {name3}}
{{tom}, {John}, {Harry}}

I tried following but it didnt work because it is expecting regular txt file instead of the arrays
string[] str = File.ReadAllLines("filepath");

in my case I have to read arrays from the file instead of simple text
how to do it best?

Thanks

推荐答案

我可以建议使用正则表达式吗?
http://msdn.microsoft.com/en-us/library/ms228595 (v = vs.80).aspx [
May I suggest using Regular Expressions?
http://msdn.microsoft.com/en-us/library/ms228595(v=vs.80).aspx[^]

You can also write your own code, but I feel like you might not be understanding what File.ReadAllLines("filepath"); is actually doing. That function won''t parse based on values, just read all the text from each line.


这篇关于从文件中读取字符串数组并在datagrid中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆