字符串的子字符串 [英] Substring of a string
问题描述
大家好,
我有一些值,例如
1)https://www.facebook.com/pages/Delhi/Shemrock-Chain-of-Preschools/359534360364
2)http://twitter.com/#!/ShemrockGroup
3)http://www.youtube.com/user/shemrocknurseryrhyme
我可以从第一个字符串中分割Facebook,从第二个字符串中分离Twitter,从第二个字符串中分离YouTube吗..
问题是,我想只分割域名部分的网址是什么..
为服务处理FoloOn零件了
谁能帮我...
谢谢Advance
Hi all,
I have some values like
1)https://www.facebook.com/pages/Delhi/Shemrock-Chain-of-Preschools/359534360364
2)http://twitter.com/#!/ShemrockGroup
3)http://www.youtube.com/user/shemrocknurseryrhyme
can i split facebook from first string, twitter from second,youtube from thiird string ..
The problem is that what ever may the url i want to split just Domainname part only..
It is fro handling FoloOn part for a Service
Can anybody help me...
Thank you in Advance
推荐答案
我认为Uri
类可用于从url
字符串中提取Host
名称,它可以拆分''.''
和第一个与豁免字符串不匹配的单词可以如下所示
I think theUri
class can be used to extract theHost
name from theurl
string, it can be split up with''.''
and the first word which does not match the exempted strings can be taken as shown below
string[] urls = {@"https://WWW.facebook.com/pages/Delhi/Shemrock-Chain-of-Preschools/359534360364",
@"http://twitter.com/#!/ShemrockGroup",
@"http://www.youtube.com/user/shemrocknurseryrhyme"};
foreach(string url in urls)
//"www mail" etc. to exclude the intial parts not required.
Console.WriteLine (((new Uri(url)).Host).Split('.')
.FirstOrDefault(str => !@"www mail".Contains(str.ToLower())) ?? string.Empty);
//Output
//
//facebook
//twitter
//youtube
查看此
http://forums.asp.net/t/1187298.aspx/1 [ ^ ]
http://www.jonasjohn.de/snippets/csharp/extract-domain- name-from-url.htm [ ^ ]
see this
http://forums.asp.net/t/1187298.aspx/1[^]
http://www.jonasjohn.de/snippets/csharp/extract-domain-name-from-url.htm[^]
嗨
以下答案可能对您有帮助
Hi
below answer may be helpful to you
<script type="javascript">
---
var nPage = window.location.pathname;
nPage = nPage.substring(nPage.lastIndexOf('/') + 1);
alert(npage);
您可以根据convineint更改子字符串上方的内容...</script>
you can change above substring as per convineint...</script>
这篇关于字符串的子字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!