473,387 Members | 1,535 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,387 software developers and data experts.

string help

Hi there,

I have a string containing of a letter and numbers, i.e. "B1234". How can I
saperate the numbers and the letter in two seperate strings?
string1 = B
string2 = 1234

I also have another string which looks like "B323_1234". They shoould be
seperated in to two seperate strings. Like this:
string1 = B323_
string2 = 1234

What is the best way to approach this?
Thank you very much
Chris
Nov 17 '05 #1
3 1536
Got the solution for the second string.

But I still do not knwo how to the first one. Can you just extract the first
character from a string?

Solution for second:

string strDel = "_";
char [] charDel = strDel.ToCharArray();
string [] a_strSplit = strCipidi.Split(charDel);
strFirstHalf = a_strSplit[0];
strSecondHalf = a_strSplit[1];
strFirstHalf += "_";

"chris" wrote:
Hi there,

I have a string containing of a letter and numbers, i.e. "B1234". How can I
saperate the numbers and the letter in two seperate strings?
string1 = B
string2 = 1234

I also have another string which looks like "B323_1234". They shoould be
seperated in to two seperate strings. Like this:
string1 = B323_
string2 = 1234

What is the best way to approach this?
Thank you very much
Chris

Nov 17 '05 #2
Hello,
you can achieve it using the Regular Expressions.

System.Text.RegularExpressions.Regex regEx = new
System.Text.RegularExpressions.Regex(@"[\d]+|[\D]+");
string str = "B1234";
System.Text.RegularExpressions.MatchCollection col =
regEx.Matches(str);
string string1 = str.Substring(col[0].Index,col[0].Length);
string string2 = str.Substring(col[1].Index,col[1].Length);
Console.WriteLine(string1);
Console.WriteLine(string2);

HTH :)
Maqsood Ahmed [MCP,C#]
Kolachi Advanced Technologies
http://www.kolachi.net

*** Sent via Developersdex http://www.developersdex.com ***
Nov 17 '05 #3
chris <ch***@discussions.microsoft.com> wrote:
Got the solution for the second string.

But I still do not knwo how to the first one. Can you just extract the first
character from a string?


If you want it as a character, just use the indexer:

char first = someString[0];

If you want it as a string, you might as well just use Substring.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Helmut Jarausch | last post by:
Hi, entering help('rstrip') or help('ljust') into IDLE's shell window I only get no Python documentation found ...
3
by: Imran Aziz | last post by:
Hello All, I am getting the following error on our production server, and I dont get the same error on the development box. Unable to cast object of type 'System.Byte' to type 'System.String'. ...
5
by: Sia Jai Sung | last post by:
Hi, I have a class that I modify from a sample program, like below ========================================== Imports System Imports System.Web.UI Imports System.Security.Cryptography ...
6
by: Niyazi | last post by:
Hi all, What is fastest way removing duplicated value from string array using vb.net? Here is what currently I am doing but the the array contains over 16000 items. And it just do it in 10 or...
6
by: Calros Lo | last post by:
Dear all: I develop a programe that need when I get a string , such as "123" or "ABC",if I get string "123" and the system will help me to create new string "124" , if I get string "ABC" and the...
5
by: Joe Nova | last post by:
I'm a C++ noob and I need a little help manipulating strings. I've got a program that takes an expression in the form: "operand1 operator operand2" I'd like to: 1. Find the total length...
9
by: MikeB | last post by:
Hi, I'd appreciate some help, please. I'm writing a VS2005 VB project for school and one of the requirements is that every screen should have a "Help" button. I could do it by writing a clumsy...
8
by: Lucky | last post by:
hi guys! back again with another query. the problem is like this. i want to print a line like this: "---------------------------------------------" the easiest way is to simply assign it to...
13
by: mac | last post by:
Hi, I'm trying to write a fibonacci recursive function that will return the fibonacci string separated by comma. The problem sounds like this: ------------- Write a recursive function that...
37
by: xyz | last post by:
I have a string 16:23:18.659343 131.188.37.230.22 131.188.37.59.1398 tcp 168 for example lets say for the above string 16:23:18.659343 -- time 131.188.37.230 -- srcaddress 22 ...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.