2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【C#】文字列を大文字/小文字を区別せずに置換する方法

Posted at

Windowsのパスを置換する時に大文字小文字が入り混じっていて
上手く置換出来なかったのでメモ。

string srcStr = "abc\Abc\aBc";
string dstStr = Regex.Replace(inStr, "abc", "xyz", RegexOptions.IgnoreCase);

// 結果は"xyz\xyz\xyz"になる

String.Replaceではなく**『Regex.Replace』**を使って、
引数にRegexOptions.IgnoreCaseを指定すればOK。
ついつい文字列置換=String.Replaceを使う癖がついているので
咄嗟に大文字小文字を区別せずにやる方法がわからなかった。

2
2
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?