Solved

How to parse a number from a string

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Expression Evaluater 3 46
Where does legacy ASP.NET initialize language? 2 63
C# Linq - Join two objects into one 3 37
C# DataTable (in memory) vs SQL Lookups 4 37
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.
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
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

726 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