私は質問を私がしたいこととして述べていなかったかもしれません。以下のシナリオを検討してください。
シナリオ:
C# Win Form アプリケーションに検索/置換機能を実装しています。この機能には、特定の値で「始まる」または「終わる」部分文字列を置き換えるオプションがあります。例えば:
- 文字列には が含まれます
"123ABCD"
。で置き換える"123"
と、次のように"XYZ"
なります。"XYZABCD"
- 文字列には が含まれます
"ABCD123"
。で置き換える"123"
と、次のように"XYZ"
なります。"ABCDXYZ"
これらの機能は両方とも正常に機能しています。私の問題は、文字列に"123ABCD123"
. を使用すると、両方の操作で間違った値が返されます"XYZ"
。
- 「で始まる」は
"XYZABCDXYZ"
、代わりに を生成します"XYZABCD"
- 「で終わる」は
"XYZABCDXYZ"
代わりに生成します"ABCDXYZ"
誰かがそれを達成する方法を教えてもらえますか?
ありがとう !!!
コードスニペット:
if (this.rbMatchFieldsStartedWith.Checked)
{
if (caseSencetive)
{
matched = currentCellValue.StartsWith(findWhat);
}
else
{
matched = currentCellValue.ToLower().StartsWith(findWhat.ToLower());
}
}
else if (this.rbMatchFieldsEndsWith.Checked)
{
if (caseSencetive)
{
matched = currentCellValue.EndsWith(findWhat);
}
else
{
matched = currentCellValue.ToLower().EndsWith(findWhat.ToLower());
}
}
if (matched)
{
if (replace)
{
if (this.rbMatchWholeField.Checked)
{
currentCell.Value = replaceWith;
}
else
{
currentCellValue = currentCellValue.Replace(findWhat, replaceWith);
currentCell.Value = currentCellValue;
}
this.QCGridView.RefreshEdit();
}
else
{
currentCell.Style.BackColor = Color.Aqua;
}
}