Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 63
  • Last Modified:

How to extract part of data

How can I get 10 from this data pattern?

SAQ212QQQQ | Bagoong Factory | 10


Thanks,
0
JimiJ13
Asked:
JimiJ13
  • 2
2 Solutions
 
anarki_jimbelCommented:
I'd split the string into an array and the last array item - your number.

        private void button2_Click(object sender, EventArgs e)
        {
            string pattern = @"SAQ212QQQQ | Bagoong Factory | 10";
            char[] chs = {'|'};

            string[] items = pattern.Split(chs);
           
            System.Diagnostics.Debug.WriteLine("This is your number: " + items[2]);
        }

Open in new window


Output:

This is your number:  10

Open in new window

0
 
Fernando SotoRetiredCommented:
Hi  JimiJ13;

This will do what you want.

// Test Data
string data = "SAQ212QQQQ | Bagoong Factory | 10";
// The variable ten now has the value "10"
string ten = data.Substring(data.LastIndexOf('|') + 1).Trim();

Open in new window

0
 
JimiJ13I T ConsultantAuthor Commented:
Great solutions. I like both.
0
 
Fernando SotoRetiredCommented:
Not a problem JimiJ13, glad to have been of assistance.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now