Remove remaining url after htm?

时间:2018-06-05 04:59:33

标签: c# url

i need to remove the url path starting from /deposit/jingdongpay.htm?bid=4089 '?' i just need /deposit/jingdongpay.htm. It means that the url will remove anything that comes after .htm Any idea how to do it.

2 个答案:

答案 0 :(得分:0)

在Python中,您可以使用str.split()

url = "/deposit/jingdongpay.htm?bid=4089"
split_url = url.split('?')

>>> split_url
['/deposit/jingdongpay.htm', 'bid=4089']
>>> split_url[0]
'/deposit/jingdongpay.htm'

答案 1 :(得分:0)

您可以使用String.Split方法:

string url = "/deposit/jingdongpay.htm?bid=4089";
string result = url.Split('?')[0]; 

另一种方法是使用String.Substring

string result = url.Substring(0, url.IndexOf('?'));

或许如果您对LINQ解决方案感兴趣:

string result = new string(url.TakeWhile(c => c != '?').ToArray());

result =“/ deposit /jingdongpay.htm”