Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
If I have a string value of IMG10001, and like to split it into two separate variable.

IMG10001 = IMG1 0001
Original value1 value2
string

Thank you for any input.
Posted
Comments
OriginalGriff 12-Dec-12 10:27am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
BaniXVII 12-Dec-12 19:04pm    
I am not a coder or an expert to ask a good question about C# , I am just presenting how I understand on how to split this string IMG10001 to became separate string or field on C # code.

field1 = IMG1
field2 = 0001

I am not a coder or an expert to ask a good question about C# , I am just presenting how I understand on how to split this string IMG10001 to became separate string or field on C # code.

field1 = IMG1
field2 = 0001


Ah! That makes a bit more sense. There are a large number of ways to do it, depending on the data you are dealing with. If it is fixed length - always 3 alphabetic followed by a bunch of numeris, then use the String.Substring method:
C#
string inp = "IMG0001";
string prefix = inp.Substring(0, 3);
string suffix = inp.Substring(3);
Alternatively, if the data can vary in length, then a simple Regex would do it:
C#
Regex reg = new Regex(@"(?<prefix>[A-Za-z]+)(?<suffix>\d+)");
Match m = reg.Match(inp);
if (m.Success)
    {
    prefix = m.Groups["Prefix"].Value;
    suffix = m.Groups["Suffix"].Value;
    }</suffix></prefix>
 
Share this answer
 
These should help,

http://msdn.microsoft.com/en-us/library/system.string.substring(v=vs.71).aspx[^]

http://msdn.microsoft.com/en-us/library/b873y76a.aspx[^]

With that little of information cant really give you much more,
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900