Re: Does anyone know how to split a string...

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Alexander Shirshov (alexander_at_omnitalented.com)
Date: 03/10/05


Date: Thu, 10 Mar 2005 22:23:03 +0700

A simple regex will do:

string input = "ABC001";

Regex regex = new Regex(@"(\d+)");
MatchCollection matches = regex.Matches(input);

int number = Int32.Parse(matches[0].Value);
number++;

string output = regex.Replace(input, number.ToString("000"));

HTH,
Alexander Shirshov

using System.Text.RegularE
"¶©¼z" <a@a.com> wrote in message news:42306001.2CA17A7A@a.com...
> hello, everybody
> i would like to know how to
> split a string which composed of (characters,digits)
> E.g. the string is ABC001, i would like split the "ABC" char and
> digits +1 to 002 then combine it to ABC002
>
> THX



Relevant Pages

  • Re: Does anyone know how to split a string...
    ... Alexander Shirshov wrote: ... > A simple regex will do: ... > HTH, ... >> THX ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: VIM: How to split a line on spaces?
    ... > Benjamin Esham wrote: ... >> HTH, ... I'm trying to understand this regex. ... so \S matches non-whitespace characters. ...
    (comp.editors)
  • Re: C# Regular Expressions
    ... Match match = Regex.Match(storedProc, pattern); ... MatchCollection matches = Regex.Matches(content, secondPattern); ... Both RegEx are giving the same result ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: the only difference is the x after /g
    ... /x tells sys' to ignore all white space, not just \n. ... in the first of the two regex lines. ... Look at the first regex space: ...
    (perl.beginners)
  • Re: VB.Net Open Internet Explorer
    ... HTH, ... Alexander Shirshov ... >I am currently migrating over from VB6 and I can't see to find a way to ...
    (microsoft.public.dotnet.general)