Click here to Skip to main content
14,827,050 members
Please Sign up or sign in to vote.
3.40/5 (4 votes)
See more:
I am developing a project of a medicine shop.

where I need to provide pack value e.g. 10mg, 2 mg , 10S where int as well as string value is there.

Is it possible to separate these two values and place these in different variable.
I can't use Substring() because the length of int and string are not same.

Please help me.
[no name] 1-Sep-12 9:43am
Be happy with your code.
I didn't understand people like you doesn't have any adaptation capability.
OriginalGriff 1-Sep-12 10:01am
Congratulations! You win today's star prize for the most unhelpful and stupid comment on Codeproject.
Everyone has to start somewhere: because you may understand the problem and they don't is not a reason to be rude to someone asking a sensible question. Please do not do it again.
[no name] 1-Sep-12 14:24pm
thanks OriginalGriff
OriginalGriff 2-Sep-12 2:22am
You are welcome!
[no name] 1-Sep-12 15:11pm
I didn't understand why people downrated the question even they don't understand the question or don't know the answer.
There should a mechanism in CodeProject where anyone downrate anything they need to give a reason for it.
otherwise it will be cancelled.

I'd use a Regex:
Regex regex = new Regex("(?<Number>\\d+)(?<Unit>.*)");
Match m = regex.Match("10mg");
if (m.Success)
    int number = int.Parse(m.Groups["Number"].Value);
    string unit = m.Groups["Unit"].Value;
ridoy 1-Sep-12 10:00am
good one..+5
[no name] 1-Sep-12 14:33pm
Its working perfectly
just need to add one namespace
and its done.
Thanks thanks thanks
Thank you very much.
All the code and the source was unknown to me.
I learned a new thing today.
Thanks thanks.
Can you give me a link except msdn to learn about RegularExpressions.
another extra help.
Help me.
Thanks for the code.
OriginalGriff 2-Sep-12 2:28am
Have a look at this:
It covers the basics (there is a heck of a lot of useful stuff in a regex, it is difficult to cover in a short article).

Also, get a copy of Expresso ( - it's free, and it examines, generates and tests regular expressions. It's a lovely bit of software - I use it a lot to create and test regexes, it can then auto generate the appropriate C# code for you, ready to paste into your app.
[no name] 2-Sep-12 6:38am
Thanks once again
[no name] 1-Sep-12 14:35pm
above solution worked perfectly.
So didn't take extra headache to open the link.
Thanks for the link.

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