Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 查找并操作字符串_C#_Asp.net - Fatal编程技术网

C# 查找并操作字符串

C# 查找并操作字符串,c#,asp.net,C#,Asp.net,我有一个url的路径字符串,我需要对其进行操作,以便在网站中找到实际页面 所以在url中我有这个 www.example.com/news/business/Royal baby-凯特生男孩-201306251551 我想在url的末尾找到“201307231551”,然后把它放在url的新闻标题之前。所以理想情况下,我会 www.example.com/news/business/2013/07/23/15/51/皇家婴儿-凯特生男孩 有人能帮忙吗。提前谢谢 为您的ASP.NET版本查找主题U

我有一个url的路径字符串,我需要对其进行操作,以便在网站中找到实际页面

所以在url中我有这个

www.example.com/news/business/Royal baby-凯特生男孩-201306251551

我想在url的末尾找到“201307231551”,然后把它放在url的新闻标题之前。所以理想情况下,我会

www.example.com/news/business/2013/07/23/15/51/皇家婴儿-凯特生男孩


有人能帮忙吗。提前谢谢

为您的ASP.NET版本查找主题URL重写。 然后,从字符串:

www.example.com/news/business/Royal baby-凯特生男孩-201306251551“

您可以使用类似的正则表达式:
(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})
。每个组代表您需要的部分信息

祝你好运


将站点用作帮助程序

string strInputstring = @"www.example.com/news/business/Royal baby - Kate gives birth to boy-201306251551";
string strRegex = @"(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})";
RegexOptions myRegexOptions = RegexOptions.None;
Regex myRegex = new Regex(strRegex, myRegexOptions);

foreach (Match myMatch in myRegex.Matches(strInputstring))
{
  if (myMatch.Success)
  {

    //myMatch.Groups[0].Value  <-  contains 2013.
    //myMatch.Groups[1].Value  <-  contains 06   
    //myMatch.Groups[2].Value  <-  contains 25   
    //myMatch.Groups[3].Value  <-  contains 15   
    //myMatch.Groups[4].Value  <-  contains 51   

  }
}
strInputstring=@“www.example.com/news/business/Royal baby-凯特生男孩-201306251551”;
字符串stregex=@“(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})”;
RegexOptions myRegexOptions=RegexOptions.None;
正则表达式myRegex=新正则表达式(strRegex,myRegexOptions);
foreach(在myRegex.Matches中匹配myMatch(strInputstring))
{
如果(myMatch.Success)
{

//myMatch.Groups[0]。值您的原始URL包含“201306251551”而不是“201307231551”".我猜这是一个输入错误?而且,如果你知道URL的末尾有一个固定长度的序列,那么提取这个值就很容易了。你向一个不熟悉字符串操作的人扔了一个正则表达式?他们需要的不仅仅是运气。是的,特别是因为Kate已经在分娩了。Michael是个骗子ht,我对正则表达式一点也不熟悉。在网上找到了一些关于“regex.Replace”的示例,但是我如何在正则表达式匹配后将“201307231551”修改为/2013/07/23/15/51/呢?我已经更新了答案,使其更有帮助。