使用正则表达式替换数据集中的所有字符串 [英] replace all strings from dataset by using regex

查看:110
本文介绍了使用正则表达式替换数据集中的所有字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

开发者们!
我是Vishal Sharma.
我的问题是我有一个csv文件,可以包含1 MB数据,并且csv文件在数据集中加载并显示在DataGridView中,数据包含多个列或行的正则表达式;我不知道哪些列包含正则表达式,所以我想替换数据集中所有列或行上的方法.
我有一个包含System.Text.Regex的代码,用于替换每行,但是我不知道如何在参数中使用所有行.

代码是:

Hi developers!
I''m Vishal Sharma.
My problem is I have a csv file that can contain 1 MB data and csv file loads in the dataset and shows in DataGridView, data contains a Regular Expression in multiple columnns or rows; I do not know which columns contain regular expressions, so I want replace mehod work on all the columns or rows in the dataset.
I have a code that contains System.Text.Regex for replace each rows but I do not know how all the rows taken in a parameter.

The code is:

string str = ",";
string mtr = "/";
foreach (DataRow datarow in dataset.Tables[0].Rows)
    {
        datarow[]= regex.replace(str.tostring, mtr.tostring)
    }


数据行索引我想获取所有行,而不是单个行,并且我不希望数据集中有更多行.

请立即解决此代码
为什么?你是我的老板吗?


The datarow index I want to take all the rows, not a single row and I do not how more rows in my dataset.

please solve this code imediatly
Why? Are you my boss?

推荐答案

维沙尔先生尝试这样,

Mr Vishal try like this,

string str = ",";
string mtr = "/";
foreach (DataRow datarow in dataset.Tables[0].Rows)
 {
   foreach(DataColumn datacol in dataset.Tables[0].Columns)
   {
     datarow[datacol]= regex.Replace(datarow[datacol].ToString(), str.tostring, mtr.tostring);
   }
}



如果有帮助,请标记为答案".



Mark as Answer if it helps.


这篇关于使用正则表达式替换数据集中的所有字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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