CodeKeep C# Feed Gennaio 7th, 2008
Description: Getting the binding element from the current DataContext
Link:
http://www.codekeep.net/snippets/b88e163f-46da-41c1-b56d-f2d5112bfda8.aspxprivate Binding GetBinding(string path)
{
Binding binding1 = new Binding();
binding1.Source = this.DataContext;
binding1.Mode = BindingMode.Default;
binding1.Path = new PropertyPath(path);
return binding1;
}
CodeKeep C# Feed Gennaio 7th, 2008
Description: Obfuscates email addresses found in given string
Link:
http://www.codekeep.net/snippets/ef09155a-04df-44ea-9d90-bf6661392a98.aspxprotected string obfuscate(string input)
{
string email = string.Empty;
MatchCollection matches = Regex.Matches(input, @"[a-zA-Z]+[a-zA-Z0-9]*[\.|\-|_]?[a-zA-Z0-9]+@([a-zA-Z]+[a-zA-Z0-9]*[\.|\-|_]?[a-zA-Z]+[a-zA-Z0-9]*[a-zA-Z0-9]+){1,4}\.[a-zA-Z]{2,4}", RegexOptions.Singleline | RegexOptions.IgnoreCase);
foreach (Match match in matches)
{
email = string.Empty;
Array matcharray = match.Value.ToCharArray();
foreach (char letter in matcharray)
{
email += "&#" + Convert.ToInt32(letter).ToString() + ";";
}
input = input.Substring(0, match.Index)+email+input.Substring((match.Index+match.Length));
}
return input;
}