C#Regex在“后加数字”$1“;
所以我做了类似的事情C#Regex在“后加数字”$1“;,c#,regex,C#,Regex,所以我做了类似的事情 extern const BP_UINT8 g_SysMapDis_0[]; 因此,如何在“$1”之后追加一个数字?您的正则表达式需要遵循,因为这是您试图替换的字符串 $10[];// should be "extern const BP_UINT8 g_SysMapDis_0[];" 补充意见 请注意,您可以使用更简单的字符串。在本例中,请替换,而不是使用正则表达式 extern const BP_UINT8 g_SysMapDis_0[]; string ret=
extern const BP_UINT8 g_SysMapDis_0[];
因此,如何在“$1”之后追加一个数字?您的正则表达式需要遵循,因为这是您试图替换的字符串
$10[];// should be "extern const BP_UINT8 g_SysMapDis_0[];"
补充意见
请注意,您可以使用更简单的字符串。在本例中,请替换,而不是使用正则表达式
extern const BP_UINT8 g_SysMapDis_0[];
string ret=codeBlock.Replace(“,n.ToString());
在这种简单的情况下,您可以使用字符串替换而不是正则表达式:
string ret = codeBlock.Replace("<DIST_N>", n.ToString());
另见:
代码块。替换(“,0)
?我同意,但答案更符合原始操作。字符串替换在这里就足够了。也许我可以添加它作为注释。”
"(<DIST_N>)"
Regex REGEX_CODE_BLOCK_DIST_N = new Regex(@"(<DIST_N>)");
int n = 0;
string codeBlock = "extern const BP_UINT8 g_SysMapDis_<DIST_N>[];";
string ret = REGEX_CODE_BLOCK_DIST_N.Replace(codeBlock, n.ToString() );
extern const BP_UINT8 g_SysMapDis_0[];
string ret = codeBlock.Replace("<DIST_N>", n.ToString());
string codeBlock = "extern const BP_UINT8 g_SysMapDis_<DIST_N>[];";
string ret = codeBlock.Replace("<DIST_N>", "0");
var s = Regex.Replace("123abc",@"(.)","${1}0");