473,395 Members | 1,348 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,395 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 1537
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: 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.