Link to home
Start Free TrialLog in
Avatar of ITsolutionWizard
ITsolutionWizardFlag for United States of America

asked on

c# special format

my string x will come from xml file and I do not know how many items will be there. may 10, may 100.
And now I want to extract as below. How can I do that in c#?


string x = [KDAV(100),KDX(200),CSGW(300)]

extract to

string model = "KDAV,KDX,CSGW";
string qty = "100,200,300";
Avatar of Daniel Van Der Werken
Daniel Van Der Werken
Flag of United States of America image

This works:

       
static void Main(string[] args)
        {
            string x = "[KDAV(100),KDX(200),CSGW(300)]";

            x = x.Replace("[", string.Empty);
            x = x.Replace("]", string.Empty);
            x = x.Replace(")", string.Empty);
            string[] y = x.Split(new char[] { ',' });

            string model = string.Empty;
            string qty = string.Empty;

            for (int i = 0; i < y.Length; i++)
            {
                string[] z = y[i].Split(new char[] { '(' });
                model += z[0] + ",";
                qty += z[1] + ",";
            }

            model = model.Remove(model.Length - 1, 1);
            qty = qty.Remove(qty.Length - 1, 1);
        }

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Fernando Soto
Fernando Soto
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial