473,396 Members | 1,996 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Does anyone know how to split a string...

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
5 2370
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Juho Saarikko | last post by:
The program attached to this message makes the Python interpreter segfault randomly. I have tried both Python 2.2 which came with Debian Stable, and self-compiled Python 2.3.3 (newest I could find...
5
by: Colleyville Alan | last post by:
I have an application that uses SQL. I am writing a new piece to it, so I used the same approach that worked before. I set up a string and add to it, i.e. strMySql = "some Sql Statement" and then...
2
by: Elhanan | last post by:
hi all.. i have the following string: 200850625~01~464~^^200850625~01~464~^^200850625~01~908~^^ which i will need to turn to a mutli-dimentional string array i used result.Split(new...
1
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= | last post by:
I get the above error in some of the ASP.NET web applications on a server, and I need some help figuring out how to deal with it. This is a rather long post, and I hope I have enough details that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.