Solved

How to parse a number from a string

Posted on 2004-08-30
1
234 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

828 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