如何打破URL的字符串? [英] how to break the string of URLs?

查看:63
本文介绍了如何打破URL的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一串URL,我需要使用http作为索引来破坏URL .Below是我的字符串示例。

string X = http://www.yachtbroker.dk/ _publicPics / Boats443B.JPGhttp://www.yachtbroker.dk/_publicPics/Boats/543B.gifhttp://yachtbrokerdk/_publicPics/Boats/idue.jpeg



how实现它?

I have a string of URLs and i need to break the urls using "http" as index.Below is my string example.
string X= http://www.yachtbroker.dk/_publicPics/Boats443B.JPGhttp://www.yachtbroker.dk/_publicPics/Boats/543B.gifhttp://yachtbrokerdk/_publicPics/Boats/idue.jpeg

how to achieve it?

推荐答案

有两种方法:

There are a couple of ways:
string[] urls = inputString.Split(new string[] {"http://"}, StringSplitOptions.RemoveEmptyEntries);

是最简单的,但如果以后需要,你需要将http://部分添加回每个字符串。



替代方法是使用正则表达式,这有点复杂,但可以保留完整的URL。

Is the simplest, but you will need to add the "http://" part back onto each string if you need it later.

The alternative is to use a Regex, which is a little more complex, but could preserve the complete URL.


Hi Ahmed



用户RE GEX解决它..





尝试这样..



Hi Ahmed

user REGEX to resolve it..


try like this..

string url = "http://www.yachtbroker.dk/_pblicPics/Boats443B.JPGhttp://www.yachtbroker.dk/_publicPics/Boats/543B.gifhttp://yachtbrokerdk/_publicPics/Boats/idue.jpeg";
             string[] urls = Regex.Split(url, @"http://");









删除数组中的空字符串。

使用此...







to remove the empty string in the array.
use this..

string[] urls = Regex.Split(url, @"http://").Where(k => !string.IsNullOrWhiteSpace(k)).ToArray();







尝试此代码...

< br $>





try this code...


string url = "http://www.yachtbroker.dk/_publicPics/Boats443B.JPGhttp://www.yachtbroker.dk/_publicPics/Boats/543B.gifhttp://yachtbrokerdk/_publicPics/Boats/idue.jpeg";

              string token = "http://";
              var urls = url.Split(new string[] { token }, StringSplitOptions.RemoveEmptyEntries).Select(k => token + k).ToArray();


尝试下面的代码

try below code
string X = "http://www.yachtbroker.dk/_publicPics/Boats443B.JPGhttp://www.yachtbroker.dk/_publicPics/Boats/543B.gifhttp://yachtbrokerdk/_publicPics/Boats/idue.jpeg";
 
string[] values = X.Split(new string[] { "http" }, StringSplitOptions.None);


这篇关于如何打破URL的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆