By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,671 Members | 1,387 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,671 IT Pros & Developers. It's quick & easy.

Does anyone know how to split a string...

P: n/a
z
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
Nov 16 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
I would use a regular expression for this. Check out the classes in the
System.Text.RegularExpressions namespace for the RegEx class. You can use
that to split apart the string easily. Once you have the parts, just use
the static ToInt32 method on the Convert class, or the static Parse method
on the Int32 structure to parse the number out, add one to it, and then
recreate the string.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"z" <a@a.com> wrote in message news:42***************@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

Nov 16 '05 #2

P: n/a
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:42***************@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

Nov 16 '05 #3

P: n/a
z
cheers

"Nicholas Paldino [.NET/C# MVP]" wrote:

I would use a regular expression for this. Check out the classes in the
System.Text.RegularExpressions namespace for the RegEx class. You can use
that to split apart the string easily. Once you have the parts, just use
the static ToInt32 method on the Convert class, or the static Parse method
on the Int32 structure to parse the number out, add one to it, and then
recreate the string.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"z" <a@a.com> wrote in message news:42***************@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

Nov 16 '05 #4

P: n/a
hi,

you can use a regex for this , "\w+\d+" should be good to start with.

If you do not like them, then string.IndexOfAny( new char[] {
'1','2',....} ) should help you.

cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"z" <a@a.com> wrote in message news:42***************@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

Nov 16 '05 #5

P: n/a
z
cheers

Alexander Shirshov wrote:

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:42***************@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

Nov 16 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.