?
Solved

How to parse a number from a string

Posted on 2004-08-30
1
Medium Priority
?
237 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 37

Accepted Solution

by:
gregoryyoung earned 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

764 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