使用C#将数据拆分并保存在列表中 [英] Split and save data in list using C#

查看:85
本文介绍了使用C#将数据拆分并保存在列表中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

h, 我的网格中有一列[Invoice_No].值就像
"120号发票"
我只需要将120保存到一个整数列表中,如何在asp.net应用程序中使用c#保存它. .pls可以帮助我..预先感谢.

h, I have a column [Invoice_No] in my grid. the values are like
"Invoice # 120 "
I need to save only 120 from this into an integer list.How can i save this using c# in my asp.net application. .pls help me..thanks in advance.

推荐答案

尝试一下

Try this

string txt = "Invoice # 120";

        string[] txt1 = txt.Split('#');
        Response.Write(txt1[1].Trim());



谢谢



Thanks


尝试一下

try this

List<string> strlist = new List<string>();
           strlist.Add("Invoice # 120 ");
           strlist.Add("Invoice # 130 ");
           strlist.Add("Invoice # 140 ");
           List<int> intlist=new List<int>();

           foreach (String str in strlist)
           {
               intlist.Add(Convert.ToInt32(Regex.Match(str, @"\d+").Value));
           }


根据您的要求尝试以下代码:


Try below code according to your requirement:


 string[] ArrInvoice = { "Invoice # 120", "Invoice # 121", "Invoice # 122", "Invoice # 123" };
            List<int> lstInvice = new List<int>();
            foreach (string item in ArrInvoice)
            {
                int intInvocie = 0;               
                Int32.TryParse(item.Split('#')[1], out intInvocie);
                if (intInvocie>0)
                {
                    lstInvice.Add(intInvocie);
                }
            }
</int></int>



希望这能满足您的要求.
不要忘记标记此答案,如果发现它有用的话

谢谢,
Arshad



Hope this will fulfill your requirement.
Dont Forget to mark this answer, if find it is useful

Thanks,
Arshad


这篇关于使用C#将数据拆分并保存在列表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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