本文整理汇总了C#中System.Text.RegularExpressions.Regex.Replace方法的典型用法代码示例。如果您正苦于以下问题:C# System.Text.RegularExpressions.Regex.Replace方法的具体用法?C# System.Text.RegularExpressions.Regex.Replace怎么用?C# System.Text.RegularExpressions.Regex.Replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Text.RegularExpressions.Regex
的用法示例。
在下文中一共展示了System.Text.RegularExpressions.Regex.Replace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Html2String
/// <summary>
/// Html到文本
/// </summary>
/// <param name="Html"></param>
/// <param name="html"></param>
/// <returns></returns>
public static string Html2String(this HtmlHelper Html, string html)
{
System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[/s/S]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[/s/S]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" no[/s/S]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[/s/S]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[/s/S]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex(@"/<img[^/>]+/>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"</p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"<p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex9 = new System.Text.RegularExpressions.Regex(@"<[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
html = regex1.Replace(html, ""); //过滤<script></script>标记
html = regex1.Replace(html, ""); //过滤<script></script>标记
html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性
html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
html = regex4.Replace(html, ""); //过滤iframe
html = regex5.Replace(html, ""); //过滤frameset
html = regex6.Replace(html, ""); //过滤frameset
html = regex7.Replace(html, ""); //过滤frameset
html = regex8.Replace(html, ""); //过滤frameset
html = regex9.Replace(html, "");
html = html.Replace(" ", " ");
html = html.Replace("</strong>", "");
html = html.Replace("<strong>", "");
return html;
}
示例2: VerifSaisie
private string VerifSaisie(string numero)
{
Boolean plusEnPremier = false;
String resultatfinal = "";
numero = numero.Trim();
//filtre regex on ne garde que ce qui est chiffre et '+'
System.Text.RegularExpressions.Regex myRegex = new System.Text.RegularExpressions.Regex("[^0-9+]");
string resultat1 = myRegex.Replace(numero, "");
if (resultat1.Length > 0)//Si le résultat du premier chiffre donne autre chose qu'une chainbe vide on continue
{
if (resultat1[0] == '+')//on verifie si le premier élement de la collection de caractére est un "+", si oui on valorise un booleen
{ plusEnPremier = true; }
myRegex = new System.Text.RegularExpressions.Regex("[^0-9]");//on garde que les chiffres dans la chaine
}
//test du boleen si oui on rajoute le caractére '+'
if (plusEnPremier)
{
resultatfinal = "+" + myRegex.Replace(resultat1, "");
}
else
{
resultatfinal = myRegex.Replace(resultat1, "");
}
return resultatfinal; //renvoi la chaine modifiée
}
示例3: CheckStr
/// 过滤html,js,css代码
/// <summary>
/// 过滤html,js,css代码
/// </summary>
/// <param name="html">参数传入</param>
/// <returns></returns>
public static string CheckStr(string html)
{
System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[\s\S]+</script. *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[\s\S]*script. *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" no[\s\S]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[\s\S]+</iframe. *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[\s\S]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex(@"\<img[^\>]+\>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"</p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"<p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex9 = new System.Text.RegularExpressions.Regex(@"<[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
html = regex1.Replace(html, ""); //过滤<script></script>标记
html = regex2.Replace(html, ""); //过滤href=java script. (<A>) 属性
html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
html = regex4.Replace(html, ""); //过滤iframe
html = regex5.Replace(html, ""); //过滤frameset
html = regex6.Replace(html, ""); //过滤frameset
html = regex7.Replace(html, ""); //过滤frameset
html = regex8.Replace(html, ""); //过滤frameset
html = regex9.Replace(html, "");
html = html.Replace(" ", "");
html = html.Replace("</strong>", "");
html = html.Replace("<strong>", "");
html = html.Replace("'", "'");
return html;
}
示例4: CleanHTML
/// <summary>
/// 清除HTML代码
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public static string CleanHTML(string text)
{
var regex = new System.Text.RegularExpressions.Regex(@"(<[a-zA-Z].*?>)|(<[\/][a-zA-Z].*?>)");
var content = regex.Replace(text, string.Empty);
content = content.Replace(" ", " ");
return content;
}
示例5: ReplaceFileIDRecycleNames
private static string ReplaceFileIDRecycleNames(string metafileText, string oldPrefix, string newPrefix)
{
string fileIDPattern = "([\\d]{8}: )" + oldPrefix;
var fileIDRegex = new System.Text.RegularExpressions.Regex(fileIDPattern);
string replacementText = "$1" + newPrefix;
return fileIDRegex.Replace(metafileText, replacementText);
}
示例6: GetDocElement
public string GetDocElement(string elementName)
{
var htmlDoc = new HtmlAgilityPack.HtmlDocument();
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"[\t\n\r]+");
htmlDoc.LoadHtml(this._html);
switch (elementName)
{
case "Title":
return regex.Replace(htmlDoc.DocumentNode.SelectNodes("div[@id='METADATA']/div[@id='TITLE']")[0].InnerText, " ");
case "Description":
return regex.Replace(HttpUtility.HtmlDecode(htmlDoc.DocumentNode.SelectNodes("div[@id='METADATA']/div[@id='DESCRIPTION']")[0].InnerText), " ");
default:
return "";
}
}
示例7: ReplaceSpriteMetaData
private static string ReplaceSpriteMetaData(string metafileText, string oldPrefix, string newPrefix)
{
string spritenamePattern = "(- name: )" + oldPrefix;
var spritenameRegex = new System.Text.RegularExpressions.Regex(spritenamePattern);
string replacementText = "$1" + newPrefix;
return spritenameRegex.Replace(metafileText, replacementText);
}
示例8: ReturnErrorMessages
/// <summary>
/// Return Error Messages
/// </summary>
/// <param name="errors"></param>
/// <returns></returns>
public static List<String> ReturnErrorMessages(IEnumerable errors)
{
var r = new System.Text.RegularExpressions.Regex(@"
(?<=[A-Z])(?=[A-Z][a-z]) |
(?<=[^A-Z])(?=[A-Z]) |
(?<=[A-Za-z])(?=[^A-Za-z])", System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace);
List<String> errorMessages = new List<String>();
foreach (System.Web.Http.ModelBinding.ModelState state in errors)
{
foreach (var error in state.Errors)
{
if (error.Exception != null)
{
string[] objectProperty = error.Exception.ToString().Split(Convert.ToChar("'"));
if (objectProperty.Length > 2)
{
string errorMessage = r.Replace(objectProperty[1], " ");
errorMessages.Add(errorMessage + " is invalid.");
}
else
{
errorMessages.Add(error.Exception.ToString());
}
}
}
}
return errorMessages;
}
示例9: ReturnErrorMessages
/// <summary>
/// Return Error Messages
/// </summary>
/// <param name="errors"></param>
/// <returns></returns>
public static List<String> ReturnErrorMessages(IEnumerable errors)
{
var r = new System.Text.RegularExpressions.Regex(@"
(?<=[A-Z])(?=[A-Z][a-z]) |
(?<=[^A-Z])(?=[A-Z]) |
(?<=[A-Za-z])(?=[^A-Za-z])", System.Text.RegularExpressions.RegexOptions.IgnorePatternWhitespace);
List<String> errorMessages = new List<String>();
foreach (KeyValuePair<string, string[]> item in errors)
{
string errorMessage;
string keyValue = item.Key;
string[] objectProperty = keyValue.Split(Convert.ToChar("."));
if (objectProperty.Length == 0)
errorMessage = item.Value[0];
else
{
errorMessage = objectProperty[1] + ": " + item.Value[0];
if (errorMessage.Contains(objectProperty[1]))
{
errorMessage = errorMessage.Replace(objectProperty[1], "");
errorMessage = objectProperty[1] + errorMessage;
errorMessage = errorMessage.Replace(" for ", "");
}
}
errorMessage = r.Replace(errorMessage, " ");
errorMessage = errorMessage.Replace(" .", ".");
errorMessages.Add(errorMessage);
}
return errorMessages;
}
示例10: ParseCookieSettings
private System.Net.CookieContainer ParseCookieSettings(string line)
{
System.Net.CookieContainer container = new System.Net.CookieContainer();
// クッキー情報の前についているよくわからないヘッダー情報を取り除く
// 対象:
// \\xと2桁の16進数値
// \\\\
// \がない場合の先頭1文字
string matchPattern = "^(\\\\x[0-9a-fA-F]{2})|^(\\\\\\\\)|^(.)|[\"()]";
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(matchPattern, System.Text.RegularExpressions.RegexOptions.Compiled);
string[] blocks = line.Split(new string[] { "\\0\\0\\0" }, StringSplitOptions.RemoveEmptyEntries);
foreach (string block in blocks) {
if (block.Contains("=") && block.Contains("domain")) {
string header = reg.Replace(block, "");
System.Net.Cookie cookie = ParseCookie(header);
if (cookie != null) {
try {
container.Add(cookie);
} catch(Exception ex) {
CookieGetter.Exceptions.Enqueue(ex);
}
}
}
}
return container;
}
示例11: CompressContent
public string CompressContent(string content)
{
string pattern = "(?<!\\\")debugger(?<!\\\");";
string replacement = "eval(\"debugger;\");";
var regex = new System.Text.RegularExpressions.Regex(pattern);
content = regex.Replace(content, replacement);
return JavaScriptCompressor.Compress(content);
}
示例12: CleanInvalidXmlChars
public string CleanInvalidXmlChars(string xml)
{
string pattern = @"&#x((10?|[2-F])FFF[EF]|FDD[0-9A-F]|[19][0-9A-F]|7F|8[0-46-9A-F]|0?[1-8BCEF]);";
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(pattern, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
if (regex.IsMatch(xml))
xml = regex.Replace(xml, String.Empty);
return xml;
}
示例13: ConvertToUnsign3
public string ConvertToUnsign3(string str)
{
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("\\p{IsCombiningDiacriticalMarks}+");
string temp = str.Normalize(System.Text.NormalizationForm.FormD);
return regex.Replace(temp, String.Empty)
.Replace('\u0111', 'd').Replace('\u0110', 'D');
//return str;
}
开发者ID:nguyendanhtu,项目名称:bki-quan-ly-du-toan,代码行数:8,代码来源:F356_bao_cao_giai_ngan_quy_bt_theo_dm.aspx.cs
示例14: EducationalProgram
public EducationalProgram(string parCycle, string parActivity, string parIndex)
{
// System.Text.RegularExpressions.Regex.Replace(edProgram.Cycle, " +", " ") -- удаляет лишние пробелы в строке (к примеру заменяет два подряд на один)
System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(@"\W");
cycle = regex.Replace(parCycle, " ").Trim();
cycle = System.Text.RegularExpressions.Regex.Replace(cycle, " +", " ");
activityType= parActivity;
index = parIndex;
}
示例15: FilterParams
public static string FilterParams(string sql)
{
if (sql == null)
return null;
System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex(Gateway.Default.Db.DbProvider.ParamPrefix+ @"([\w\d_]+)");
return r.Replace(sql, "?");
}