Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,

I have a string and i want to separate string and integer value from this string.
from datagridview column value.

My data gridviewcolumn value is:-
"Customized Kreation Wardrobe 1"
"Customized Kreation Wardrobe 2"
"Customized Kreation Wardrobe 3"
"Customized Kreation Wardrobe 4"
"Customized Kreation Wardrobe n"


I want to separate whole string and integer value.

How can be possible?

Please help me.

Thanks in Advance.

Ankit Agarwal
Software Engineer
Posted
Updated 20-Mar-14 3:31am
v2
Comments
joshrduncan2012 20-Mar-14 9:22am    
Look into how strings can be split. That's all you have to do, regardless if this is in a datagridview or not.
[no name] 20-Mar-14 9:25am    
My datagridview column values:-
Product Name
"Customized Kreation Wardrobe 1"
"Customized Kreation Wardrobe 2"
"Customized Kreation Wardrobe 3"
"Customized Kreation Wardrobe 4"
"Customized Kreation Wardrobe n"

I want separate integer value and string from this column values.
It's my need.
Tejas Vaishnav 20-Mar-14 9:32am    
What will be the desired output..

1 solution

You should use regular expression like in the next example:

C#
const string expression = @"\d+$"; 
Regex regEx = new Regex(expression );
//
foreach (string item in yourStringList)
{
 Match match = regEx.Match(item);
 if(match .Success)
 {
  string intValue = match.Value;  // ==> the int part from the end!
  string messageValue = item.Substring(0, match.Index);
  //use your values
  //
 }
}
 
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