首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >c# FindTextLocation或DataGridView DataGridViewTextBoxCell中的文本索引

c# FindTextLocation或DataGridView DataGridViewTextBoxCell中的文本索引
EN

Stack Overflow用户
提问于 2019-11-21 07:12:13
回答 1查看 39关注 0票数 0

在我的应用程序中,由于获取准确的文本位置或索引,我面临着复杂的问题。我的短信就像

"AAAAAAAA“+ (......a long space.)+ "BBBBBBBB”

我可以从我的DatagridViewTextBoxCell中获得这些值作为数组。但为了突出的目的我无法找到他们的位置。请帮我解决这个问题。

在CellPainting事件下获取值的代码是

代码语言:javascript
复制
DataGridViewTextBoxCell currentCell =
    (DataGridViewTextBoxCell)grid.Rows[e.RowIndex].Cells[e.ColumnIndex]

提前感谢

EN

回答 1

Stack Overflow用户

发布于 2019-11-21 07:51:06

我不知道你的问题是如何搜索或者如何粉刷你的手机。这里是如何搜索字符串中的文本或使用正则表达式查找文本的示例。

代码语言:javascript
复制
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;
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58969183

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档