Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Usage:
- extract(textBox1.Text, textBox2.Text, 1); //returns the username
- extract(textBox1.Text, textBox2.Text, 2); //returns the password
- private string getBetween(string strSource, string strStart, string strEnd)
- {
- int Start, End;
- if (strSource.Contains(strStart) && strSource.Contains(strEnd))
- {
- Start = strSource.IndexOf(strStart, 0) + strStart.Length;
- End = strSource.IndexOf(strEnd, Start);
- return strSource.Substring(Start, End - Start);
- }
- else
- {
- return "";
- }
- }
- private string extract(String input, String format, int param)
- {
- try
- {
- String[] paramSplit;
- String username, password;
- paramSplit = System.Text.RegularExpressions.Regex.Split(format, "{#param#}");
- username = getBetween(input, paramSplit[0], paramSplit[1]);
- password = input;
- password = password.Replace(username, null);
- for (int i = 0; i < paramSplit.Count(); i++)
- {
- if (paramSplit[i].Length != 0)
- {
- password = password.Replace(paramSplit[i], null);
- }
- }
- String[] result = { username, password };
- if (param == 1) { return result[0]; }
- else
- if (param == 2) { return result[1]; }
- else
- return "Invalid Parameter";
- }
- catch (Exception ex)
- {
- return "Error";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement