如何在c#.net windows应用程序中拆分datagridview列值? [英] Hhow to split datagridview column value in c# .net windows application?
本文介绍了如何在c#.net windows应用程序中拆分datagridview列值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我想在六个变量中拆分一个datagridview列值,
我的Datagridview columna是这样的: -
Hello,
I want to split one datagridview column value in six variable,
My Datagridview columna like this:-
"\Library\Daino Royal - A.jpg,\Library\Abc.jpg,\Library\DEF.jpg,\Library\GHI.jpg,\Library\TIVOLI_GREY_A.jpg,\Library\URBANA_GREY - C.jpg"
>
我想在六个变量中仅填写.jpg文件,例如,
I want to fill only ".jpg" file in six variable like,
string a = "Abc.jpg";
那么,请帮助我如何拆分一个datagridview列值?
谢谢
Ankit Agarwal
软件工程师
So, Please help me how can we split one datagridview column value?
Thanks
Ankit Agarwal
Software Engineer
推荐答案
这是一种做法...
Here''s one way of doing it ...
// copy the dgv value to a string e.g.
string dgvCell = dataGridView1.Rows[0].Cells[0].Value.ToString();
// Remove the /libary bits
dgvCell = dgvCell.Replace(@"\Library\", "");
//Use string.split to split on commas, store results in string array
string[] jpgList = dgvCell.Split(',');
// Do something with the results e.g. ...
foreach (string j in jpgList)
if(j.Contains("jpg"))
Debug.Print(j);
也试试这个正则表达式代码
also try this regex code
string s = @"\Library\Daino Royal - A.jpg,\Library\Abc.jpg,\Library\DEF.jpg,\Library\GHI.jpg,\Library\TIVOLI_GREY_A.jpg,\Library\URBANA_GREY - C.jpg";
MatchCollection matches = Regex.Matches(s, @"(\w*.jpg)");
// or use MatchCollection matches = Regex.Matches(s, @"(\w*?\s*?-?\s*?\w*.jpg)");
//or use MatchCollection matches = Regex.Matches(s, @"((\w*?\s*?-?\s*?){0,}\w*.jpg)");
string[] imgFileName = new string[matches.Count];
int i=0;
foreach (Match match in matches)
{
imgFileName[i] = match.Value;
MessageBox.Show(match.Value);
i++;
}
这篇关于如何在c#.net windows应用程序中拆分datagridview列值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文