Csharp-substitutions

提供:Dev Guides
移動先:案内検索

C#-置換

置換は置換パターンで使用されます。 次の表は、置換を示しています-

Character Description Pattern Replacement pattern Input string Resulting string
$number Substitutes the substring matched by group number. \b(\w+)(\s)(\w+)\b $3$2$1 "one two" "two one"
$\{name*}* Substitutes the substring matched by the named groupname. \b(?< word1>\w+)(\s)(?< word2>\w+)\b ${word2} ${word1} "one two" "two one"
$$ Substitutes a literal "$". \b(\d+)\s?USD $$$1 "103 USD" "$103"
$& Substitutes a copy of the whole match. (\$(\d(\.\d)?){1}) **$& "$1.30" "$1.30"
$` Substitutes all the text of the input string before the match. B+ $` "AABBCC" "AAAACC"
$' Substitutes all the text of the input string after the match. B+ $' "AABBCC" "AACCCC"
$+ Substitutes the last group that was captured. B+(C+) $+ "AABBCCDD" AACCDD
$_ Substitutes the entire input string. B+ $_ "AABBCC" "AAAABBCCCC"