Solved

How to parse a number from a string

Posted on 2004-08-30
1
232 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
ID: 11933233
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

831 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