Advertisement
Guest User

Untitled

a guest
May 30th, 2017
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.77 KB | None | 0 0
  1.  Usage:
  2.  extract(textBox1.Text, textBox2.Text, 1); //returns the username
  3.  extract(textBox1.Text, textBox2.Text, 2); //returns the password
  4.  
  5.         private string getBetween(string strSource, string strStart, string strEnd)
  6.             {
  7.                 int Start, End;
  8.                 if (strSource.Contains(strStart) && strSource.Contains(strEnd))
  9.                 {
  10.                     Start = strSource.IndexOf(strStart, 0) + strStart.Length;
  11.                     End = strSource.IndexOf(strEnd, Start);
  12.                     return strSource.Substring(Start, End - Start);
  13.                 }
  14.                 else
  15.                 {
  16.                     return "";
  17.                 }
  18.             }
  19.         private string extract(String input, String format, int param)
  20.         {
  21.             try
  22.             {
  23.                 String[] paramSplit;
  24.                 String username, password;
  25.                 paramSplit = System.Text.RegularExpressions.Regex.Split(format, "{#param#}");
  26.                 username = getBetween(input, paramSplit[0], paramSplit[1]);
  27.                 password = input;
  28.                 password = password.Replace(username, null);
  29.                 for (int i = 0; i < paramSplit.Count(); i++)
  30.                 {
  31.                     if (paramSplit[i].Length != 0)
  32.                     {
  33.                         password = password.Replace(paramSplit[i], null);
  34.                     }
  35.                 }
  36.                 String[] result = { username, password };
  37.                 if (param == 1) { return result[0]; }
  38.                 else
  39.                     if (param == 2) { return result[1]; }
  40.                     else
  41.                         return "Invalid Parameter";
  42.             }
  43.             catch (Exception ex)
  44.             {
  45.                 return "Error";
  46.             }
  47.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement