Click here to Skip to main content
Sign Up to vote bad
good
See more: C#4.0
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 12 Dec '12 - 4:25

Comments
OriginalGriff - 12 Dec '12 - 10:27
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:04
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

3 solutions

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:
            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:
            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>
  Permalink  
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,
  Permalink  

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

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Sergey Alexandrovich Kryukov 294
1 OriginalGriff 195
2 CPallini 163
3 Mahesh Bailwal 159
4 Tadit Dash 148
0 Sergey Alexandrovich Kryukov 10,169
1 OriginalGriff 7,749
2 CPallini 4,181
3 Rohan Leuva 3,482
4 Maciej Los 3,089


Advertise | Privacy | Mobile
Web03 | 2.6.130523.1 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid