在我的应用程序中,由于获取准确的文本位置或索引,我面临着复杂的问题。我的短信就像
"AAAAAAAA“+ (......a long space.)+ "BBBBBBBB”
我可以从我的DatagridViewTextBoxCell中获得这些值作为数组。但为了突出的目的我无法找到他们的位置。请帮我解决这个问题。
在CellPainting事件下获取值的代码是
DataGridViewTextBoxCell currentCell =
(DataGridViewTextBoxCell)grid.Rows[e.RowIndex].Cells[e.ColumnIndex]提前感谢
发布于 2019-11-21 07:51:06
我不知道你的问题是如何搜索或者如何粉刷你的手机。这里是如何搜索字符串中的文本或使用正则表达式查找文本的示例。
static void Main(string[] args)
{
string someText = "AAAAAAAAAA sjkvsvkjq BBBBBBBBBBB";
// This is how to find a Text within a String:
string searchText = "BBBBBBBBBBB";
int indexOfString = someText.IndexOf(searchText);
Console.WriteLine("Text found at index " + indexOfString);
// This is how to find text within a pattern:
Regex regularExpression = new Regex("AAAAAAAAAA (.*) BBBBBBBBBBB");
string textBetweenBraces = regularExpression.Match(someText).Groups[1].ToString();
Console.WriteLine("Pattern matched. Text in Pattern: " + textBetweenBraces);
// Paint your cell:
if (regularExpression.IsMatch(someText))
{
DataGridViewTextBoxCell cell = null; // Select your cell
cell.Style.BackColor = Color.Red;
}
}https://stackoverflow.com/questions/58969183
复制相似问题