Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
private void dataGridView3_CellClick(object sender, DataGridViewCellEventArgs e)
{
connection.Open();
try
{
mdr = command.ExecuteReader();
if (mdr.Read())
{
String character = dataGridView3.CurrentRow.Cells[1].Value.ToString();

// now "character" have 7788ASD I want only "A"
//???????????????????????

}
else
{
MessageBox.Show("bla bla......");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
connection.Close();
}

What I have tried:

i hava some date all of same 7788ASD I want split and only "A" i want
Posted
Updated 25-Jan-18 23:16pm
Comments
Karthik_Mahalingam 26-Jan-18 2:57am    
what about other cases?
show other examples, like input and expected output..
based on that only the regex or the logic wll be determined.
Member 13498879 26-Jan-18 3:21am    
sij j mera tusra code nei
private void dataGridView3_CellClick(object sender, DataGridViewCellEventArgs e)
{
connection.Open();
try
{
mdr = command.ExecuteReader();
if (mdr.Read())
{
String character = dataGridView3.CurrentRow.Cells[1].Value.ToString();

if I write textbox.text = character; output s come 7788ASD come
// here split or write regex but how to I don't no
// now "character" have 7788ASD I want only "A"
//???????????????????????

}
else
{
MessageBox.Show("bla bla......");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
connection.Close();
}
Karthik_Mahalingam 26-Jan-18 4:13am    
check the solution if it helps

Try a regex:
(?<FirstNumber>\d\d)(?<SecondNumber>\d\d)(?<Char1>.)(?<Char2>.)(?<Char3>.)
That splits your input into groups: two digits, two digits, then three sets of one character.
You can then access each group as a separate object and process it without having to split it up any further. (Replace the names with descriptions of the fields).
Regex Class[^]
 
Share this answer
 
Comments
Member 13498879 26-Jan-18 2:09am    
sorry I cant understand that regex
OriginalGriff 26-Jan-18 2:11am    
Get a copy of Expresso:
http://www.ultrapico.com/Expresso.htm
It's free, and it examines and generates Regular expressions. It'll even create C# and VB code for you, ready to use!

If you are going to hack strings apart, you do need to learn regular expressions - they can save you a huge amount of code!
Member 13498879 26-Jan-18 2:46am    
I install that msi file now how to work Expresso sir
OriginalGriff 26-Jan-18 4:10am    
Look at the menu bar under "Help" - there are "Getting started" quickstarts, a tutorial, Regex reference, etc... All pretty comprehensive.
Quote:
i hava some date all of same 7788ASD I want split and only "A" i want

What about reading C# documentation?
String.Substring Method (Int32, Int32) (System)[^]
 
Share this answer
 
try
String character =   dataGridView3.CurrentRow.Cells[1].Value.ToString();
           string result = "";
           if (character.Length >= 5)
               result = character.Substring(4, 1);
 
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