Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static string CreateId(string inputstr)
- {
- char[] allowed_chars = new char[] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '_' };
- inputstr = inputstr.Replace("á", "a")
- .Replace("í", "i")
- .Replace("é", "e")
- .Replace("ó", "o")
- .Replace("ö", "o")
- .Replace("ő", "o")
- .Replace("ü", "u")
- .Replace("ú", "u")
- .Replace("ű", "u")
- .Replace("ä", "a")
- .Replace("ş", "s")
- .Replace("ô", "o")
- .Replace(" ", "_")
- .Replace("-", "_");
- StringBuilder sb = new StringBuilder();
- bool wasHyphen = true;
- foreach (char c in inputstr)
- {
- if (char.IsLetterOrDigit(c))
- {
- if (allowed_chars.Contains(c))
- {
- sb.Append(c);
- wasHyphen = false;
- }
- }
- else if (c != '\'' && !wasHyphen)
- {
- sb.Append('-');
- wasHyphen = true;
- }
- }
- // Avoid trailing hyphens
- if (wasHyphen && sb.Length > 0)
- sb.Length--;
- return sb.ToString();
- }
Advertisement
Add Comment
Please, Sign In to add comment