-7

以下のテキストから太字 (Password10) のパスワード値を抽出する必要があります。私はC#プログラミング言語を使用しています。

FName Lname、システムパスワードが変更されました。変更していない場合、または変更の理由がわからない場合は、すぐに管理者に連絡してください。新しいパスワードはPassword10です。

ご不明な点がございましたら、以下までお問い合わせください。

ソリューション プログラム オフィス 電話: Eメール: 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

私はこれをテストしませんでしたが、おそらく正しい方向に進むことができます.

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 に答える
0

RegEx (正規表現) の使用も検討してください。

于 2012-12-17T15:15:39.483 に答える