试图从长字符串中取出网址

问题描述 投票:0回答:1

我有一个很长的文本字符串,已经从sql表中隔离出来并变成了字符串;

Thank you for your request.   
Please click the following link to reset your password:
http://localhost:5692/Public/LogonSetPassword.aspx?activationLinkId=603fa657-9460-4417-adc2-7bcad0416c3e
If clicking on the link does not work then please copy and paste it directly into your browser address bar

我现在正尝试仅取出URL并将其放入另一个字符串。我需要从“ http”获取它,并使用唯一ID后面的空格结束它。

我尝试过:

string activationUrl = sql.Substring(sql.IndexOf("http", sql.IndexOf(" ")));

但是它似乎不起作用。有人可以解释我哪里出问题了吗?谢谢。

c# string substring indexof
1个回答
0
投票

应该是换行符,而不是空格。

string activationUrl = sql.Substring(sql.IndexOf("http", sql.IndexOf("\n")));
© www.soinside.com 2019 - 2024. All rights reserved.