如何在c#.net中拆分datagridview列值的字符串? [英] How to Split string of datagridview column value in c# .net?

查看:107
本文介绍了如何在c#.net中拆分datagridview列值的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,



我有一个字符串,我想从这个字符串中分离字符串和整数值。
来自datagridview列值的




我的数据gridviewcolumn值是: -

Customized Kreation Wardrobe 1
定制Kreation衣柜2
定制Kreation衣柜3
定制Kreation衣柜4
定制Kreation衣柜n





我想分隔整个字符串和整数值。



怎么可能?



请帮帮我。



先谢谢。



Ankit Agarwal

软件工程师

解决方案

您应该使用正则表达式,如下例所示:



  const   string  expression =  @  \d + 

;
Regex regEx = new 正则表达式(表达式);
//
foreach string item in yourStringList)
{
匹配匹配= regEx .Match(项目);
if (匹配.Success)
{
string intValue = match.Value; // ==>从最后开始的int部分!
string messageValue = item.Substring( 0 ,match.Index);
// 使用您的值
//
}
}


Hello,

I have a string and i want to separate string and integer value from this string.
from datagridview column value.

My data gridviewcolumn value is:-

"Customized Kreation Wardrobe 1"
"Customized Kreation Wardrobe 2"
"Customized Kreation Wardrobe 3"
"Customized Kreation Wardrobe 4"
"Customized Kreation Wardrobe n"



I want to separate whole string and integer value.

How can be possible?

Please help me.

Thanks in Advance.

Ankit Agarwal
Software Engineer

解决方案

You should use regular expression like in the next example:

const string expression = @"\d+


"; Regex regEx = new Regex(expression ); // foreach (string item in yourStringList) { Match match = regEx.Match(item); if(match .Success) { string intValue = match.Value; // ==> the int part from the end! string messageValue = item.Substring(0, match.Index); //use your values // } }


这篇关于如何在c#.net中拆分datagridview列值的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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