时间:2021-07-01 10:21:17 帮助过:3人阅读
输出模式替换结果
< ?php
//字符串
$string = "Name: {Name}< br>\nEmail:
{Email}< br>\nAddress: {Address}< br>\n";
//模式
$patterns =array(
"/{Address}/",
"/{Name}/",
"/{Email}/"
);
//替换字串
$replacements = array (
"No.5, Wilson St., New York, U.S.A",
"Thomas Ching",
"tom@emailaddress.com",
);
//
public static String PregReplace(this String input, string[] pattern, string[] replacements) {
if (replacements.Length != pattern.Length) throw new ArgumentException("Replacement and Pattern Arrays must be balanced");
for (var i = 0; i < pattern.Length; i++)
{ input = Regex.Replace(input, pattern[i], replacements[i]); }
return input;
}
http://www.bkjia.com/PHPjc/321099.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/321099.htmlTechArticle把php preg_replace 用c# 重写了一下。 PHP语言的功能非常强大,主要就是靠它强大的函数来作支撑。我们在这篇文章中将会为大家详细讲解有关...