Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 我想将文本文件加载到数据网格中,并应用正则表达式_C#_Wpf_Datagrid - Fatal编程技术网

C# 我想将文本文件加载到数据网格中,并应用正则表达式

C# 我想将文本文件加载到数据网格中,并应用正则表达式,c#,wpf,datagrid,C#,Wpf,Datagrid,我想将文本文件加载到数据网格中,并应用正则表达式 但是这段代码不适用于我您不需要正则表达式来搜索空字符串。方法就行了 private string RemoveEmptyLines(string lines) { return lines = Regex.Replace(lines, @"\n\s.+", ""); } 我想单独排除圆的一部分 string[] lines = File.ReadAllLines(ofdl.FileName); var codes = lines.Wh

我想将文本文件加载到数据网格中,并应用正则表达式


但是这段代码不适用于我

您不需要正则表达式来搜索空字符串。方法就行了

private string RemoveEmptyLines(string lines)
{
    return lines = Regex.Replace(lines, @"\n\s.+", "");
}

我想单独排除圆的一部分

string[] lines = File.ReadAllLines(ofdl.FileName);
var codes = lines.Where(s => !String.IsNullOrWhiteSpace(s)).ToList();

dataGrid.ItemsSource = codes;
under_label.Content = ofdl.FileName;
under_label1.Content = codes.Count;

哪个部分不工作?regex不适用。我不知道如何应用regexIt不是空字符串。
string[] lines = File.ReadAllLines(ofdl.FileName);
var codes = lines.Where(s => !String.IsNullOrWhiteSpace(s)).ToList();

dataGrid.ItemsSource = codes;
under_label.Content = ofdl.FileName;
under_label1.Content = codes.Count;
   List<code> codes = new List<code>();
                    string[] s = File.ReadAllLines(ofdl.FileName);

                    string textfile = ofdl.FileName;
                       var textvalues = s;

                       foreach (var item in textvalues)
                       {
                       codes.Add(new code() { Value = item});
                       }
                    dataGrid.ItemsSource = codes;



                }
            }
        }

        private void streams()
        {


        }

        private string RemoveEmptyLines(string lines)
        {
            return lines = Regex.Replace(lines, @"\n\s.+", "");
        }