我怎么能得到这个号码 [英] how can i get this number
问题描述
大家好,
这是我的网址:
http://localhost:4127/Project/articles/test-article-2766.aspx [ ^ ]
从这个网址我怎么能得到数字2766
请任何人可以帮助我.
提前谢谢.
请查看输出.我尝试了所有解决方案,但我做不到.
我给出每种解决方案的输出.
该代码有效,但是每次显示相同的数字时,它不会随url
一起改变
Hi All,
Here is my url:
http://localhost:4127/Project/articles/test-article-2766.aspx[^]
from this url how can i get the number 2766
please any one can help me.
Thanks in advance.
please see the output. i try every solution but i can''t get this.
i give the output for every solution.
this code is worked but every time display same number,it does not change along with url
string pageUrl = HttpContext.Current.Request.Url.AbsoluteUri;
if(!string.IsNullOrEmpty(pageUrl))
{
string[] arr = pageUrl.Split('-');
string ur_number = (arr[arr.Length -1]).replace(".aspx"," ");
}
我认为发生此问题是因为我正在使用URL重写器来更改URL,但是这些代码
仅从配置文件获取默认网址.请任何人帮助我
我已经在配置文件中写了
I think this problem is occured because i am using url rewriter for that it change the url but those codes
only get default url from config file. Plaese any one help me
i have write in config file
<rewriter>
<rewrite url="~/articles/(.+)-(.+).aspx" to="../articles/details.aspx?test-for-stream-5-2778"/>
</rewriter>
plesae检查这个,我认为我在URL重写中出了点问题.我给此默认网址test-for-stream-5-2778,所以每次request.url仅获取此网址.
plesae check this i think i am going something wrong in this url rewrite. i give this default url test-for-stream-5-2778 so every time request.url get this url only.
推荐答案
您需要使用正则表达式:
You need to use regular expression:
using System.Text.RegularExpressions;
Regex reg;
Match m;
string line = " http://localhost:4127/Project/articles/test-article-2766.aspx";
reg = new Regex(@"http://.*?/.*?/.*?/.*?(\d{4})");
m = reg.Match(line);
string str = m.Groups[1].ToString;
< edit>正则表达式声明错误,在字符串前添加了神奇的@
<edit>Error on Regex declaration, added the magical @ before the string
这是您的作业代码.
Hi,
Here''s the code for your assignment.
var url = @"http://localhost:4127/Project/articles/test-article-2766.aspx";
var split = url.Split('.');
if (split.Length > 0 && split[0].LastIndexOf('-') > -1) {
var articleNo = split[0].Substring(split[0].LastIndexOf('-') + 1);
Console.WriteLine(articleNo);
}
祝你好运!
Good luck!
string pageUrl = HttpContext.Current.Request.Url.AbsoluteUri;
if(!string.IsNullOrEmpty(pageUrl))
{
string[] arr = pageUrl.Split(''-'');
string ur_number = (arr[arr.Length -1]).replace(".aspx"," ");
}
这篇关于我怎么能得到这个号码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!