• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录

五蕴

  • 博客园
  • 联系
  • 订阅
  • 管理

公告

View Post

一段字符串,知道开始和结束的字符,取中间的字符

string s = "<FORM id=logInForm name=logInForm action=chk_rule.php method=post><INPUT type=hidden value=nf3a5776z23th8npzppq54z1j0d9z032 name=uid>

</FORM>";

Regex re = new Regex(@"\s+value=([^\s>]+)");

Match m = re.Match(s);
if (m.Success)
Console.WriteLine(m.Groups[1].Value);


++++++++++++++++++++++++++++++++++++++++++++++
起始,结束字符都是固定的,即不是带正则元字符的,其实用IndexOf也许更好些

string Start = "...";
string End = "...";


string s = "............";

int i = s.IndexOf(Start);
if (i >=0)
{
  int j= s.IndexOf(End, i+Start.Length);
  if (j >0)
  {
string Result = s.Substring(i+Start.Length, j-i-Start.Length);
  }
}


//********************* 正则判断是否存在某个字符串。

 //if (System.Text.RegularExpressions.Regex.IsMatch(html, "&uid="))
                            //{
                            //    return true;
                            //}

posted on 2012-11-15 10:36  五蕴  阅读(330)  评论(0)    收藏  举报

刷新页面返回顶部
 
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3