123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading.Tasks;
- namespace XYY.Common.Standard
- {
- public static class StringExp
- {
- public static string TrimEmpty(this string str)
- {
- return str.Trim('\r', '\n', '\t');
- }
- }
- public class StringHelper
- {
- public static string ReplaceNonEnglishCharaters(string raw)
- {
- if (string.IsNullOrWhiteSpace(raw)) return raw;
- StringBuilder sb = new StringBuilder(raw);
- sb = sb.Replace('Š', 'S');
- sb = sb.Replace('Œ', 'E');
- sb = sb.Replace('œ', 'a');
- sb = sb.Replace('ž', 'z');
- sb = sb.Replace('Ÿ', 'Y');
- sb = sb.Replace('¡', 'i');
- sb = sb.Replace('¢', 'c');
- sb = sb.Replace('£', 'f');
- sb = sb.Replace('À', 'A');
- sb = sb.Replace('Á', 'A');
- sb = sb.Replace('Â', 'A');
- sb = sb.Replace('Ã', 'A');
- sb = sb.Replace('Ä', 'A');
- sb = sb.Replace('Å', 'A');
- sb = sb.Replace('Æ', 'E');
- sb = sb.Replace('Ç', 'C');
- sb = sb.Replace('È', 'E');
- sb = sb.Replace('É', 'E');
- sb = sb.Replace('Ê', 'E');
- sb = sb.Replace('Ë', 'E');
- sb = sb.Replace('Ì', 'I');
- sb = sb.Replace('Î', 'I');
- sb = sb.Replace('Ï', 'I');
- sb = sb.Replace('Ð', 'D');
- sb = sb.Replace('Ñ', 'N');
- sb = sb.Replace('Ò', 'O');
- sb = sb.Replace('Ó', 'O');
- sb = sb.Replace('Ô', 'O');
- sb = sb.Replace('Õ', 'O');
- sb = sb.Replace('Ù', 'U');
- sb = sb.Replace('Ú', 'U');
- sb = sb.Replace('Ü', 'U');
- sb = sb.Replace('Ý', 'Y');
- sb = sb.Replace('Þ', 'p');
- sb = sb.Replace('ß', 'b');
- sb = sb.Replace('á', 'a');
- sb = sb.Replace('ã', 'a');
- sb = sb.Replace('ä', 'a');
- sb = sb.Replace('å', 'a');
- sb = sb.Replace('æ', 'a');
- sb = sb.Replace('ç', 'c');
- sb = sb.Replace('é', 'e');
- sb = sb.Replace('ê', 'e');
- sb = sb.Replace('ë', 'e');
- sb = sb.Replace('ì', 'i');
- sb = sb.Replace('í', 'i');
- sb = sb.Replace('î', 'i');
- sb = sb.Replace('ï', 'i');
- sb = sb.Replace('ð', 'o');
- sb = sb.Replace('ñ', 'n');
- sb = sb.Replace('ò', 'o');
- sb = sb.Replace('ô', 'o');
- sb = sb.Replace('õ', 'o');
- sb = sb.Replace('ú', 'u');
- sb = sb.Replace('ý', 'y');
- sb = sb.Replace('þ', 'p');
- sb = sb.Replace('Û', 'U');
- sb = sb.Replace('à', 'a');
- sb = sb.Replace('ā', 'a');
- sb = sb.Replace('â', 'a');
- sb = sb.Replace('è', 'e');
- sb = sb.Replace('ù', 'u');
- sb = sb.Replace('û', 'u');
- sb = sb.Replace('Í', 'I');
- sb = sb.Replace('ó', 'o');
- sb = sb.Replace('Ö', 'O');
- sb = sb.Replace('ö', 'o');
- sb = sb.Replace('ü', 'u');
- sb = sb.Replace('ľ', 'I');
- sb = sb.Replace('ļ', '1');
- sb = sb.Replace('ī', 'i');
- sb = sb.Replace('ň', 'n');
- sb = sb.Replace('ņ', 'n');
- sb = sb.Replace('č', 'c');
- sb = sb.Replace('ē', 'e');
- sb = sb.Replace('ĕ', 'e');
- sb = sb.Replace('л', 'n');
- sb = sb.Replace('и', 'N');
- sb = sb.Replace('д', 'A');
- sb = sb.Replace('ė', 'e');
- sb = sb.Replace('ū', 'u');
- sb = sb.Replace('ů', 'u');
- sb = sb.Replace('ř', 'r');
- sb = sb.Replace('ě', 'e');
- sb = sb.Replace('ő', 'o');
- sb = sb.Replace('ć', 'c');
- raw = sb.ToString();
- string pattern = "[^A-Za-z0-9]";
- var result = Regex.Replace(raw, pattern, string.Empty);
- return result;
- }
- }
- }
|