Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
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 5:25am
Comments
OriginalGriff at 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 at 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
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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
0 Maciej Los 199
1 Sergey Alexandrovich Kryukov 154
2 Sascha Lefévre 120
3 Abhinav S 104
4 Rana Waqas 78
0 Sergey Alexandrovich Kryukov 6,628
1 OriginalGriff 6,298
2 Peter Leow 2,534
3 Maciej Los 2,437
4 Abhinav S 2,378


Advertise | Privacy | Mobile
Web01 | 2.8.150414.1 | Last Updated 13 Dec 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100