问题描述
大家好,
我正在使用datagridview中的FIND和REPLACE功能。
以下是处理后的结果。
S.No
-----
CODE0001
CODE0002
CODE0003
CODE0004
其中S.No是列名。
当我找到0001并要求用1000替换它时,结果是,
S 。没有
-----
code1000
CODE0002
CODE0003
CODE0004
查找和替换功能正在运行,但大写的文字正在改为LOWERCASE。
查找和替换代码:
Hi All,
I'm working on FIND and REPLACE functionality in datagridview.
Below is the result after working on it.
S.No
-----
CODE0001
CODE0002
CODE0003
CODE0004
Where S.No is column name.
When i FIND 0001 and ask to replace that with 1000, the result is,
S.No
-----
code1000
CODE0002
CODE0003
CODE0004
Find and Replace functionality is working but the text from UPPERCASE is changing to LOWERCASE.
[edit]
Code for Find and Replace:
for (int i = 0; i <= dataGridView1.Rows.Count - 1; i++)
{
if (dataGridView1.Rows[i].Cells[f.cmbColumnCombo.Text].Value.ToString().ToLower().Contains(f.txtfind.Text.ToLower()))
{
dataGridView1.Rows[i].Cells[f.cmbColumnCombo.Text].Value = dataGridView1.Rows[i].Cells[f.cmbColumnCombo.Text].Value.ToString().ToLower().Replace(f.txtfind.Text.ToLower(), f.txtreplace.Text);
bulidDataRow(i);
}
}
推荐答案
... = ... .ToLower().Replace(f.txtfind.Text.ToLower(), f.txtreplace.Text);
你是在更换操作之前和期间降低您的数据,因此结果将始终为小写。
考虑使用Regex.Replace,它具有不区分大小写的版本:
[]
You are lower casing your data before and during the Replace operation, so the result will always be lower case.
Consider using a Regex.Replace instead, which has a case insensitive version:
Regex.Replace Method (String, String, String, RegexOptions) (System.Text.RegularExpressions)[^]
这篇关于在查找和替换时,数据从大写字母变为小写字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!