-7

我需要从下面给出的文本中提取以粗体显示的密码值 (Password10)。我正在使用 c# 编程语言。

FName Lname,您的系统密码已更改。如果您没有更改或不知道更改原因,请立即联系管理员。您的新密码是Password10

如果您有任何问题,请联系:

解决方案计划办公室电话:电子邮件:notifications@cho.com

感谢您使用 xxxxx

4

4 回答 4

2

好吧,如果您确定这将是文本呈现的形式。总是。然后,您可以简单地执行以下操作:

string text = //load your text here;
int startingIndex = text.IndexOf("Your new password is ") + "Your new password is ".Length;
string newText = text.SubString(startingIndex, text.length); //this will load all your text after the password.
//then load the first word
string password = newText.Split(' ')[0];
于 2012-12-17T15:14:45.430 回答
0

你可以使用string.Substring

int indexOfPasswordText = text.IndexOf("Your new password is ");
if (indexOfPasswordText != -1)
{
    int passwordStart = indexOfPasswordText + "Your new password is ".Length;
    int indexeOfNextWord = text.IndexOfAny(new[] { '\n', '\r', ' ' }, passwordStart);
    if (indexeOfNextWord == -1) indexeOfNextWord = text.Length;
    string passWord = text.Substring(passwordStart, indexeOfNextWord - passwordStart);
    Console.Write(passWord);
}

演示

于 2012-12-17T15:21:13.420 回答
0

您也可以考虑使用 RegEx(正则表达式)。

于 2012-12-17T15:15:39.483 回答
0

我没有对此进行测试,但也许它可以将您推向正确的方向。

string input = [YOUR MAIL];
string regex = @"Your new password is (\w+)";
Match m = Regex.Match(input, regex);
if (m.Success) {
    string password= m.Groups[1].Value;
    //do something
}
于 2012-12-17T15:39:26.003 回答