日期:2014-05-17 浏览次数:20850 次
/// <summary>
/// 获得字符串中开始和结束字符串中间得值
/// </summary>
/// <param name="str">字符串</param>
/// <param name="s">开始</param>
/// <param name="e">结束</param>
/// <returns></returns>
public static string GetValue(string filePath, string s, string e)
{
string str = System.IO.File.ReadAllText(filePath);
Regex rg = new Regex("(?<=(" + s + "))[.\\s\\S]*?(?=(" + e + "))", RegexOptions.Multiline | RegexOptions.Singleline);
return rg.Match(str).Value;
}
string reg = "(?<=[$]).*?(?=[$])";
string sss = "fjksdjfk$fesdfdds$ asss$dfdsfd$";
foreach (Match item in Regex.Matches(sss, reg))
{
Console.WriteLine(item.Value);
}
string test = "fjksdjfk$fesdfdds$ asss$dfdsfd$";
Regex reg = new Regex(@"\$[^$]+\$");
string result = reg.Replace(test, "$你要替换的内容$");
richTextBox2.Text = result;
/*-----输出-----
fjksdjfk$你要替换的内容$ asss$你要替换的内容$
*/