Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

Try this

C#
string txt = "Invoice # 120";

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


Thanks
 
Share this answer
 
Comments
[no name] 10-Oct-12 8:34am    
my 5
try this

XML
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));
           }
 
Share this answer
 
Try below code according to your requirement:


C#
 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>


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

Thanks,
Arshad
 
Share this answer
 
v2
Comments
Member 10416306 21-Nov-13 6:15am    
Pls provide
Complete code for invoice for a crm in asp.net
Hi ,

you can do this in many ways -

Solution1:
you can fetch only integer from any string using regular expression.
1.add this namespace
C#
using System.Text.RegularExpressions;

2. Fetch only numeric value
string[] status = Regex.Split(gridview.cell[0].tostring(), @"\D+");


3.put this in you list
C#
List<int> list = new List<int>();
    list.Add(status[0]);
    list.Add(status[0]);
    list.Add(status[0]);

Solution2:
split your string where getting # ->
C#
string abc = "aaa#12";  //put here your gridview text
           string[] cdf = abc.Split('#');

i have just given you idea using above you can solve your proble .:) happy coding dear :)
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900