public static class RegexReplace
{
public static void WriteHtml(string Content, string URL)
{
try
{
using (StreamWriter sw = new StreamWriter(HttpContext.Current.Server.MapPath(URL), false, System.Text.Encoding.GetEncoding("utf-8")))
{
sw.WriteLine(Content);
sw.Flush();
sw.Close();
}
}
catch (Exception EX)
{
}
}
public static string FileContent(string URL)
{
string filePath = HttpContext.Current.Server.MapPath(URL);
string fileContent = string.Empty;
using (var reader = new StreamReader(filePath))
{
fileContent = reader.ReadToEnd();
}
return fileContent;
}
/// <summary>
///
/// </summary>
/// <param name="source"></param>
/// <param name="s"></param>
/// <param name="e"></param>
/// <returns></returns>
public static string SubstringSingle(string source, string s, string e)
{
Regex rg = new Regex("(?<=(" + s + "))[.\\s\\S]*?(?=(" + e + "))", RegexOptions.Multiline | RegexOptions.Singleline);
return rg.Match(source).Value;
}
public static string Subreplace(string source, string s, string e, string modify)
{
string result = Regex.Replace(source, "((" + s + "))[.\\s\\S]*?((" + e + "))", modify);
return result;
}
}
其他
最新推荐文章于 2024-09-23 16:32:06 发布