Solved

How to parse a number from a string

Posted on 2004-08-30
1
229 Views
Last Modified: 2010-04-15
Hello

I have barcode string of the format "0804PAR000004", Another example would be "0504JOML0000007"

I want to get the last 6 digits of the barcode as an integer, increment it and append it back to the string.

For eg. "0804PAR000004" would go to "0804PAR000005"

Any ideas of an efficient was to do this?

0
Comment
Question by:auk_ie
1 Comment
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 500 total points
Comment Utility
using System;

namespace ConsoleApplication18
{
      /// <summary>
      /// Summary description for Class1.
      /// </summary>
      class Class1
      {
            /// <summary>
            /// The main entry point for the application.
            /// </summary>
            private static int getnumber(string foo) {
                  if(foo.Length > 6) {
                        string tmp = foo.Substring(foo.Length - 6, 6);
                        return int.Parse(tmp);
                  }
                  return -1;
            }

            [STAThread]
            static void Main(string[] args)
            {
                  string code = "0804PAR000004";
                  Console.Write(getnumber(code));
            }
      }
}
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now