我有一些日期相同的7788ASD,我想分开,只有“a”我想要 [英] I hava some date all of same 7788ASD I want split and only "a" I want
问题描述
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();
//现在character有7788ASD我只想要A
// ?????????????????????
}
else
{
MessageBox.Show(bla bla ......);
}
}
catch(exception ex)
{
MessageBox.Show(ex.Message);
}
connection.Close();
}
我尝试了什么:
i hava一些日期全部相同7788ASD我想拆分而且只有A我想要
尝试一个正则表达式:
(?< FirstNumber> \\\)(?< SecondNumber> \\ \\d\ d)(?< Char1>。)(?< Char2>。)(?< char3>。)将您的输入分成组:两位数,两位数,然后三组一个字符。
然后,您可以将每个组作为单独的对象访问并处理它,而无需进一步拆分。 (将名称替换为字段描述)。
Regex Class [ ^ ]
< blockquote>
引用:我hava一些日期全部相同的7788ASD我想拆分而只有A我想要
阅读C#文档怎么样?
String.Substring方法(Int32,Int32)(系统) [ ^ ]
try
String character = dataGridView3.CurrentRow .Cells [1] .Value.ToString();
string result =;
if(character.Length> = 5)
result = character.Substring(4,1);
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
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[^]
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)[^]
try
String character = dataGridView3.CurrentRow.Cells[1].Value.ToString(); string result = ""; if (character.Length >= 5) result = character.Substring(4, 1);
这篇关于我有一些日期相同的7788ASD,我想分开,只有“a”我想要的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!