PageRenderTime 50ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/SubSonic/Sugar/Strings.cs

http://github.com/subsonic/SubSonic-2.0
C# | 758 lines | 539 code | 43 blank | 176 comment | 21 complexity | 7d37b3601228b0f3897abe6747bb8df4 MD5 | raw file
  1. /*
  2. * SubSonic - http://subsonicproject.com
  3. *
  4. * The contents of this file are subject to the Mozilla Public
  5. * License Version 1.1 (the "License"); you may not use this file
  6. * except in compliance with the License. You may obtain a copy of
  7. * the License at http://www.mozilla.org/MPL/
  8. *
  9. * Software distributed under the License is distributed on an
  10. * "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
  11. * implied. See the License for the specific language governing
  12. * rights and limitations under the License.
  13. */
  14. using System;
  15. using System.Collections.Generic;
  16. using System.Text;
  17. using System.Text.RegularExpressions;
  18. using SubSonic.Utilities;
  19. namespace SubSonic.Sugar
  20. {
  21. /// <summary>
  22. /// Summary for the Strings class
  23. /// </summary>
  24. public static class Strings
  25. {
  26. private static readonly Dictionary<int, string> _entityTable = new Dictionary<int, string>();
  27. private static readonly Dictionary<string, string> _USStateTable = new Dictionary<string, string>();
  28. /// <summary>
  29. /// Initializes the <see cref="Strings"/> class.
  30. /// </summary>
  31. static Strings()
  32. {
  33. FillEntities();
  34. FillUSStates();
  35. }
  36. /// <summary>
  37. /// Strips the last specified chars from a string.
  38. /// </summary>
  39. /// <param name="sourceString">The source string.</param>
  40. /// <param name="removeFromEnd">The remove from end.</param>
  41. /// <returns></returns>
  42. public static string Chop(string sourceString, int removeFromEnd)
  43. {
  44. string result = sourceString;
  45. if((removeFromEnd > 0) && (sourceString.Length > removeFromEnd - 1))
  46. result = result.Remove(sourceString.Length - removeFromEnd, removeFromEnd);
  47. return result;
  48. }
  49. /// <summary>
  50. /// Strips the last specified chars from a string.
  51. /// </summary>
  52. /// <param name="sourceString">The source string.</param>
  53. /// <param name="backDownTo">The back down to.</param>
  54. /// <returns></returns>
  55. public static string Chop(string sourceString, string backDownTo)
  56. {
  57. int removeDownTo = sourceString.LastIndexOf(backDownTo);
  58. int removeFromEnd = 0;
  59. if(removeDownTo > 0)
  60. removeFromEnd = sourceString.Length - removeDownTo;
  61. string result = sourceString;
  62. if(sourceString.Length > removeFromEnd - 1)
  63. result = result.Remove(removeDownTo, removeFromEnd);
  64. return result;
  65. }
  66. /// <summary>
  67. /// Removes the specified chars from the beginning of a string.
  68. /// </summary>
  69. /// <param name="sourceString">The source string.</param>
  70. /// <param name="removeFromBeginning">The remove from beginning.</param>
  71. /// <returns></returns>
  72. public static string Clip(string sourceString, int removeFromBeginning)
  73. {
  74. string result = sourceString;
  75. if(sourceString.Length > removeFromBeginning)
  76. result = result.Remove(0, removeFromBeginning);
  77. return result;
  78. }
  79. /// <summary>
  80. /// Removes chars from the beginning of a string, up to the specified string
  81. /// </summary>
  82. /// <param name="sourceString">The source string.</param>
  83. /// <param name="removeUpTo">The remove up to.</param>
  84. /// <returns></returns>
  85. public static string Clip(string sourceString, string removeUpTo)
  86. {
  87. int removeFromBeginning = sourceString.IndexOf(removeUpTo);
  88. string result = sourceString;
  89. if(sourceString.Length > removeFromBeginning && removeFromBeginning > 0)
  90. result = result.Remove(0, removeFromBeginning);
  91. return result;
  92. }
  93. /// <summary>
  94. /// Strips the last char from a a string.
  95. /// </summary>
  96. /// <param name="sourceString">The source string.</param>
  97. /// <returns></returns>
  98. public static string Chop(string sourceString)
  99. {
  100. return Chop(sourceString, 1);
  101. }
  102. /// <summary>
  103. /// Strips the last char from a a string.
  104. /// </summary>
  105. /// <param name="sourceString">The source string.</param>
  106. /// <returns></returns>
  107. public static string Clip(string sourceString)
  108. {
  109. return Clip(sourceString, 1);
  110. }
  111. /// <summary>
  112. /// Returns text that is located between the startText and endText tags.
  113. /// </summary>
  114. /// <param name="sourceString">The source string.</param>
  115. /// <param name="startText">The text from which to start the crop</param>
  116. /// <param name="endText">The endpoint of the crop</param>
  117. /// <returns></returns>
  118. public static string Crop(string sourceString, string startText, string endText)
  119. {
  120. int startIndex = sourceString.IndexOf(startText, StringComparison.CurrentCultureIgnoreCase);
  121. if(startIndex == -1)
  122. return String.Empty;
  123. startIndex += startText.Length;
  124. int endIndex = sourceString.IndexOf(endText, startIndex, StringComparison.CurrentCultureIgnoreCase);
  125. if(endIndex == -1)
  126. return String.Empty;
  127. return sourceString.Substring(startIndex, endIndex - startIndex);
  128. }
  129. /// <summary>
  130. /// Removes excess white space in a string.
  131. /// </summary>
  132. /// <param name="sourceString">The source string.</param>
  133. /// <returns></returns>
  134. public static string Squeeze(string sourceString)
  135. {
  136. char[] delim = {' '};
  137. string[] lines = sourceString.Split(delim, StringSplitOptions.RemoveEmptyEntries);
  138. StringBuilder sb = new StringBuilder();
  139. foreach(string s in lines)
  140. {
  141. if(!String.IsNullOrEmpty(s.Trim()))
  142. sb.Append(s + " ");
  143. }
  144. //remove the last pipe
  145. string result = Chop(sb.ToString());
  146. return result.Trim();
  147. }
  148. /// <summary>
  149. /// Creates a string array based on the words in a sentence
  150. /// </summary>
  151. /// <param name="sourceString">The source string.</param>
  152. /// <returns></returns>
  153. public static string[] ToWords(string sourceString)
  154. {
  155. string result = sourceString.Trim();
  156. return result.Split(new char[] {' '}, StringSplitOptions.RemoveEmptyEntries);
  157. }
  158. /// <summary>
  159. /// Strips all HTML tags from a string
  160. /// </summary>
  161. /// <param name="htmlString">The HTML string.</param>
  162. /// <returns></returns>
  163. public static string StripHTML(string htmlString)
  164. {
  165. return StripHTML(htmlString, String.Empty);
  166. }
  167. /// <summary>
  168. /// Strips all HTML tags from a string and replaces the tags with the specified replacement
  169. /// </summary>
  170. /// <param name="htmlString">The HTML string.</param>
  171. /// <param name="htmlPlaceHolder">The HTML place holder.</param>
  172. /// <returns></returns>
  173. public static string StripHTML(string htmlString, string htmlPlaceHolder)
  174. {
  175. const string pattern = @"<(.|\n)*?>";
  176. string sOut = Regex.Replace(htmlString, pattern, htmlPlaceHolder);
  177. sOut = sOut.Replace("&nbsp;", String.Empty);
  178. sOut = sOut.Replace("&amp;", "&");
  179. sOut = sOut.Replace("&gt;", ">");
  180. sOut = sOut.Replace("&lt;", "<");
  181. return sOut;
  182. }
  183. [Obsolete("Will be removed in future versions. Use Validation.IsEmail instead")]
  184. public static bool IsValidEmail(string emailAddressString)
  185. {
  186. return Validation.IsEmail(emailAddressString);
  187. }
  188. /// <summary>
  189. /// Convert string to proper case
  190. /// </summary>
  191. /// <param name="sourceString">The source string.</param>
  192. /// <returns></returns>
  193. public static string ToProper(string sourceString)
  194. {
  195. string propertyName = Inflector.ToPascalCase(sourceString);
  196. //if(propertyName.EndsWith("TypeCode"))
  197. // propertyName = propertyName.Substring(0, propertyName.Length - 4);
  198. return propertyName;
  199. }
  200. /// <summary>
  201. /// Converts a generic List collection to a single comma-delimitted string.
  202. /// </summary>
  203. /// <param name="list">The list.</param>
  204. /// <returns></returns>
  205. public static string ToDelimitedList(List<string> list)
  206. {
  207. return ToDelimitedList(list, ",");
  208. }
  209. /// <summary>
  210. /// Converts a generic List collection to a single string using the specified delimitter.
  211. /// </summary>
  212. /// <param name="list">The list.</param>
  213. /// <param name="delimiter">The delimiter.</param>
  214. /// <returns></returns>
  215. public static string ToDelimitedList(List<string> list, string delimiter)
  216. {
  217. StringBuilder sb = new StringBuilder();
  218. foreach(string s in list)
  219. sb.Append(String.Concat(s, delimiter));
  220. string result = sb.ToString();
  221. result = Chop(result);
  222. return result;
  223. }
  224. /// <summary>
  225. /// Converts an array of strings to a single string using the specified delimitter.
  226. /// </summary>
  227. /// <param name="list">The list.</param>
  228. /// <param name="delimiter">The delimiter.</param>
  229. /// <returns></returns>
  230. public static string ToDelimitedList(string[] list, string delimiter)
  231. {
  232. StringBuilder sb = new StringBuilder();
  233. foreach(string s in list)
  234. sb.Append(String.Concat(s, delimiter));
  235. string result = sb.ToString();
  236. result = Chop(result);
  237. return result;
  238. }
  239. /// <summary>
  240. /// Camels to proper.
  241. /// </summary>
  242. /// <param name="sourceString">The source string.</param>
  243. /// <returns></returns>
  244. public static string CamelToProper(string sourceString)
  245. {
  246. return Utility.ParseCamelToProper(sourceString);
  247. }
  248. /// <summary>
  249. /// Plurals to singular.
  250. /// </summary>
  251. /// <param name="sourceString">The source string.</param>
  252. /// <returns></returns>
  253. public static string PluralToSingular(string sourceString)
  254. {
  255. return Inflector.MakeSingular(sourceString);
  256. }
  257. /// <summary>
  258. /// Singulars to plural.
  259. /// </summary>
  260. /// <param name="sourceString">The source string.</param>
  261. /// <returns></returns>
  262. public static string SingularToPlural(string sourceString)
  263. {
  264. return Inflector.MakePlural(sourceString);
  265. }
  266. /// <summary>
  267. /// Make plural when count is not one
  268. /// </summary>
  269. /// <param name="number">The number of things</param>
  270. /// <param name="sourceString">The source string.</param>
  271. /// <returns></returns>
  272. public static string Pluralize(int number, string sourceString)
  273. {
  274. if(number == 1)
  275. return String.Concat(number, " ", Inflector.MakeSingular(sourceString));
  276. return String.Concat(number, " ", Inflector.MakePlural(sourceString));
  277. }
  278. /// <summary>
  279. /// Strips the specified input.
  280. /// </summary>
  281. /// <param name="sourceString">The source string.</param>
  282. /// <param name="stripValue">The strip value.</param>
  283. /// <returns></returns>
  284. public static string Strip(string sourceString, string stripValue)
  285. {
  286. if(!String.IsNullOrEmpty(stripValue))
  287. {
  288. string[] replace = stripValue.Split(new char[] {','});
  289. for(int i = 0; i < replace.Length; i++)
  290. {
  291. if(!String.IsNullOrEmpty(sourceString))
  292. sourceString = Regex.Replace(sourceString, replace[i], String.Empty);
  293. }
  294. }
  295. return sourceString;
  296. }
  297. /// <summary>
  298. /// Replaces most non-alpha-numeric chars
  299. /// </summary>
  300. /// <param name="sourceString">The source string.</param>
  301. /// <returns></returns>
  302. public static string StripNonAlphaNumeric(string sourceString)
  303. {
  304. return Utility.StripNonAlphaNumeric(sourceString);
  305. }
  306. /// <summary>
  307. /// Replaces most non-alpha-numeric chars
  308. /// </summary>
  309. /// <param name="sourceString">The source string.</param>
  310. /// <param name="cReplace">The placeholder character to use for replacement</param>
  311. /// <returns></returns>
  312. public static string StripNonAlphaNumeric(string sourceString, char cReplace)
  313. {
  314. return Utility.StripNonAlphaNumeric(sourceString, cReplace);
  315. }
  316. /// <summary>
  317. /// Converts ASCII encoding to Unicode
  318. /// </summary>
  319. /// <param name="asciiCode">The ASCII code.</param>
  320. /// <returns></returns>
  321. public static string AsciiToUnicode(int asciiCode)
  322. {
  323. Encoding ascii = Encoding.UTF32;
  324. char c = (char)asciiCode;
  325. Byte[] b = ascii.GetBytes(c.ToString());
  326. return ascii.GetString((b));
  327. }
  328. /// <summary>
  329. /// Converts Text to HTML-encoded string
  330. /// </summary>
  331. /// <param name="textString">The text string.</param>
  332. /// <returns></returns>
  333. public static string TextToEntity(string textString)
  334. {
  335. foreach(KeyValuePair<int, string> key in _entityTable)
  336. textString = textString.Replace(AsciiToUnicode(key.Key), key.Value);
  337. return textString.Replace(AsciiToUnicode(38), "&amp;");
  338. }
  339. /// <summary>
  340. /// Converts HTML-encoded bits to Text
  341. /// </summary>
  342. /// <param name="entityText">The entity text.</param>
  343. /// <returns></returns>
  344. public static string EntityToText(string entityText)
  345. {
  346. entityText = entityText.Replace("&amp;", "&");
  347. foreach(KeyValuePair<int, string> key in _entityTable)
  348. entityText = entityText.Replace(key.Value, AsciiToUnicode(key.Key));
  349. return entityText;
  350. }
  351. /// <summary>
  352. /// Fills the entities.
  353. /// </summary>
  354. private static void FillEntities()
  355. {
  356. _entityTable.Add(160, "&nbsp;");
  357. _entityTable.Add(161, "&iexcl;");
  358. _entityTable.Add(162, "&cent;");
  359. _entityTable.Add(163, "&pound;");
  360. _entityTable.Add(164, "&curren;");
  361. _entityTable.Add(165, "&yen;");
  362. _entityTable.Add(166, "&brvbar;");
  363. _entityTable.Add(167, "&sect;");
  364. _entityTable.Add(168, "&uml;");
  365. _entityTable.Add(169, "&copy;");
  366. _entityTable.Add(170, "&ordf;");
  367. _entityTable.Add(171, "&laquo;");
  368. _entityTable.Add(172, "&not;");
  369. _entityTable.Add(173, "&shy;");
  370. _entityTable.Add(174, "&reg;");
  371. _entityTable.Add(175, "&macr;");
  372. _entityTable.Add(176, "&deg;");
  373. _entityTable.Add(177, "&plusmn;");
  374. _entityTable.Add(178, "&sup2;");
  375. _entityTable.Add(179, "&sup3;");
  376. _entityTable.Add(180, "&acute;");
  377. _entityTable.Add(181, "&micro;");
  378. _entityTable.Add(182, "&para;");
  379. _entityTable.Add(183, "&middot;");
  380. _entityTable.Add(184, "&cedil;");
  381. _entityTable.Add(185, "&sup1;");
  382. _entityTable.Add(186, "&ordm;");
  383. _entityTable.Add(187, "&raquo;");
  384. _entityTable.Add(188, "&frac14;");
  385. _entityTable.Add(189, "&frac12;");
  386. _entityTable.Add(190, "&frac34;");
  387. _entityTable.Add(191, "&iquest;");
  388. _entityTable.Add(192, "&Agrave;");
  389. _entityTable.Add(193, "&Aacute;");
  390. _entityTable.Add(194, "&Acirc;");
  391. _entityTable.Add(195, "&Atilde;");
  392. _entityTable.Add(196, "&Auml;");
  393. _entityTable.Add(197, "&Aring;");
  394. _entityTable.Add(198, "&AElig;");
  395. _entityTable.Add(199, "&Ccedil;");
  396. _entityTable.Add(200, "&Egrave;");
  397. _entityTable.Add(201, "&Eacute;");
  398. _entityTable.Add(202, "&Ecirc;");
  399. _entityTable.Add(203, "&Euml;");
  400. _entityTable.Add(204, "&Igrave;");
  401. _entityTable.Add(205, "&Iacute;");
  402. _entityTable.Add(206, "&Icirc;");
  403. _entityTable.Add(207, "&Iuml;");
  404. _entityTable.Add(208, "&ETH;");
  405. _entityTable.Add(209, "&Ntilde;");
  406. _entityTable.Add(210, "&Ograve;");
  407. _entityTable.Add(211, "&Oacute;");
  408. _entityTable.Add(212, "&Ocirc;");
  409. _entityTable.Add(213, "&Otilde;");
  410. _entityTable.Add(214, "&Ouml;");
  411. _entityTable.Add(215, "&times;");
  412. _entityTable.Add(216, "&Oslash;");
  413. _entityTable.Add(217, "&Ugrave;");
  414. _entityTable.Add(218, "&Uacute;");
  415. _entityTable.Add(219, "&Ucirc;");
  416. _entityTable.Add(220, "&Uuml;");
  417. _entityTable.Add(221, "&Yacute;");
  418. _entityTable.Add(222, "&THORN;");
  419. _entityTable.Add(223, "&szlig;");
  420. _entityTable.Add(224, "&agrave;");
  421. _entityTable.Add(225, "&aacute;");
  422. _entityTable.Add(226, "&acirc;");
  423. _entityTable.Add(227, "&atilde;");
  424. _entityTable.Add(228, "&auml;");
  425. _entityTable.Add(229, "&aring;");
  426. _entityTable.Add(230, "&aelig;");
  427. _entityTable.Add(231, "&ccedil;");
  428. _entityTable.Add(232, "&egrave;");
  429. _entityTable.Add(233, "&eacute;");
  430. _entityTable.Add(234, "&ecirc;");
  431. _entityTable.Add(235, "&euml;");
  432. _entityTable.Add(236, "&igrave;");
  433. _entityTable.Add(237, "&iacute;");
  434. _entityTable.Add(238, "&icirc;");
  435. _entityTable.Add(239, "&iuml;");
  436. _entityTable.Add(240, "&eth;");
  437. _entityTable.Add(241, "&ntilde;");
  438. _entityTable.Add(242, "&ograve;");
  439. _entityTable.Add(243, "&oacute;");
  440. _entityTable.Add(244, "&ocirc;");
  441. _entityTable.Add(245, "&otilde;");
  442. _entityTable.Add(246, "&ouml;");
  443. _entityTable.Add(247, "&divide;");
  444. _entityTable.Add(248, "&oslash;");
  445. _entityTable.Add(249, "&ugrave;");
  446. _entityTable.Add(250, "&uacute;");
  447. _entityTable.Add(251, "&ucirc;");
  448. _entityTable.Add(252, "&uuml;");
  449. _entityTable.Add(253, "&yacute;");
  450. _entityTable.Add(254, "&thorn;");
  451. _entityTable.Add(255, "&yuml;");
  452. _entityTable.Add(402, "&fnof;");
  453. _entityTable.Add(913, "&Alpha;");
  454. _entityTable.Add(914, "&Beta;");
  455. _entityTable.Add(915, "&Gamma;");
  456. _entityTable.Add(916, "&Delta;");
  457. _entityTable.Add(917, "&Epsilon;");
  458. _entityTable.Add(918, "&Zeta;");
  459. _entityTable.Add(919, "&Eta;");
  460. _entityTable.Add(920, "&Theta;");
  461. _entityTable.Add(921, "&Iota;");
  462. _entityTable.Add(922, "&Kappa;");
  463. _entityTable.Add(923, "&Lambda;");
  464. _entityTable.Add(924, "&Mu;");
  465. _entityTable.Add(925, "&Nu;");
  466. _entityTable.Add(926, "&Xi;");
  467. _entityTable.Add(927, "&Omicron;");
  468. _entityTable.Add(928, "&Pi;");
  469. _entityTable.Add(929, "&Rho;");
  470. _entityTable.Add(931, "&Sigma;");
  471. _entityTable.Add(932, "&Tau;");
  472. _entityTable.Add(933, "&Upsilon;");
  473. _entityTable.Add(934, "&Phi;");
  474. _entityTable.Add(935, "&Chi;");
  475. _entityTable.Add(936, "&Psi;");
  476. _entityTable.Add(937, "&Omega;");
  477. _entityTable.Add(945, "&alpha;");
  478. _entityTable.Add(946, "&beta;");
  479. _entityTable.Add(947, "&gamma;");
  480. _entityTable.Add(948, "&delta;");
  481. _entityTable.Add(949, "&epsilon;");
  482. _entityTable.Add(950, "&zeta;");
  483. _entityTable.Add(951, "&eta;");
  484. _entityTable.Add(952, "&theta;");
  485. _entityTable.Add(953, "&iota;");
  486. _entityTable.Add(954, "&kappa;");
  487. _entityTable.Add(955, "&lambda;");
  488. _entityTable.Add(956, "&mu;");
  489. _entityTable.Add(957, "&nu;");
  490. _entityTable.Add(958, "&xi;");
  491. _entityTable.Add(959, "&omicron;");
  492. _entityTable.Add(960, "&pi;");
  493. _entityTable.Add(961, "&rho;");
  494. _entityTable.Add(962, "&sigmaf;");
  495. _entityTable.Add(963, "&sigma;");
  496. _entityTable.Add(964, "&tau;");
  497. _entityTable.Add(965, "&upsilon;");
  498. _entityTable.Add(966, "&phi;");
  499. _entityTable.Add(967, "&chi;");
  500. _entityTable.Add(968, "&psi;");
  501. _entityTable.Add(969, "&omega;");
  502. _entityTable.Add(977, "&thetasym;");
  503. _entityTable.Add(978, "&upsih;");
  504. _entityTable.Add(982, "&piv;");
  505. _entityTable.Add(8226, "&bull;");
  506. _entityTable.Add(8230, "&hellip;");
  507. _entityTable.Add(8242, "&prime;");
  508. _entityTable.Add(8243, "&Prime;");
  509. _entityTable.Add(8254, "&oline;");
  510. _entityTable.Add(8260, "&frasl;");
  511. _entityTable.Add(8472, "&weierp;");
  512. _entityTable.Add(8465, "&image;");
  513. _entityTable.Add(8476, "&real;");
  514. _entityTable.Add(8482, "&trade;");
  515. _entityTable.Add(8501, "&alefsym;");
  516. _entityTable.Add(8592, "&larr;");
  517. _entityTable.Add(8593, "&uarr;");
  518. _entityTable.Add(8594, "&rarr;");
  519. _entityTable.Add(8595, "&darr;");
  520. _entityTable.Add(8596, "&harr;");
  521. _entityTable.Add(8629, "&crarr;");
  522. _entityTable.Add(8656, "&lArr;");
  523. _entityTable.Add(8657, "&uArr;");
  524. _entityTable.Add(8658, "&rArr;");
  525. _entityTable.Add(8659, "&dArr;");
  526. _entityTable.Add(8660, "&hArr;");
  527. _entityTable.Add(8704, "&forall;");
  528. _entityTable.Add(8706, "&part;");
  529. _entityTable.Add(8707, "&exist;");
  530. _entityTable.Add(8709, "&empty;");
  531. _entityTable.Add(8711, "&nabla;");
  532. _entityTable.Add(8712, "&isin;");
  533. _entityTable.Add(8713, "&notin;");
  534. _entityTable.Add(8715, "&ni;");
  535. _entityTable.Add(8719, "&prod;");
  536. _entityTable.Add(8721, "&sum;");
  537. _entityTable.Add(8722, "&minus;");
  538. _entityTable.Add(8727, "&lowast;");
  539. _entityTable.Add(8730, "&radic;");
  540. _entityTable.Add(8733, "&prop;");
  541. _entityTable.Add(8734, "&infin;");
  542. _entityTable.Add(8736, "&ang;");
  543. _entityTable.Add(8743, "&and;");
  544. _entityTable.Add(8744, "&or;");
  545. _entityTable.Add(8745, "&cap;");
  546. _entityTable.Add(8746, "&cup;");
  547. _entityTable.Add(8747, "&int;");
  548. _entityTable.Add(8756, "&there4;");
  549. _entityTable.Add(8764, "&sim;");
  550. _entityTable.Add(8773, "&cong;");
  551. _entityTable.Add(8776, "&asymp;");
  552. _entityTable.Add(8800, "&ne;");
  553. _entityTable.Add(8801, "&equiv;");
  554. _entityTable.Add(8804, "&le;");
  555. _entityTable.Add(8805, "&ge;");
  556. _entityTable.Add(8834, "&sub;");
  557. _entityTable.Add(8835, "&sup;");
  558. _entityTable.Add(8836, "&nsub;");
  559. _entityTable.Add(8838, "&sube;");
  560. _entityTable.Add(8839, "&supe;");
  561. _entityTable.Add(8853, "&oplus;");
  562. _entityTable.Add(8855, "&otimes;");
  563. _entityTable.Add(8869, "&perp;");
  564. _entityTable.Add(8901, "&sdot;");
  565. _entityTable.Add(8968, "&lceil;");
  566. _entityTable.Add(8969, "&rceil;");
  567. _entityTable.Add(8970, "&lfloor;");
  568. _entityTable.Add(8971, "&rfloor;");
  569. _entityTable.Add(9001, "&lang;");
  570. _entityTable.Add(9002, "&rang;");
  571. _entityTable.Add(9674, "&loz;");
  572. _entityTable.Add(9824, "&spades;");
  573. _entityTable.Add(9827, "&clubs;");
  574. _entityTable.Add(9829, "&hearts;");
  575. _entityTable.Add(9830, "&diams;");
  576. _entityTable.Add(34, "&quot;");
  577. //_entityTable.Add(38, "&amp;");
  578. _entityTable.Add(60, "&lt;");
  579. _entityTable.Add(62, "&gt;");
  580. _entityTable.Add(338, "&OElig;");
  581. _entityTable.Add(339, "&oelig;");
  582. _entityTable.Add(352, "&Scaron;");
  583. _entityTable.Add(353, "&scaron;");
  584. _entityTable.Add(376, "&Yuml;");
  585. _entityTable.Add(710, "&circ;");
  586. _entityTable.Add(732, "&tilde;");
  587. _entityTable.Add(8194, "&ensp;");
  588. _entityTable.Add(8195, "&emsp;");
  589. _entityTable.Add(8201, "&thinsp;");
  590. _entityTable.Add(8204, "&zwnj;");
  591. _entityTable.Add(8205, "&zwj;");
  592. _entityTable.Add(8206, "&lrm;");
  593. _entityTable.Add(8207, "&rlm;");
  594. _entityTable.Add(8211, "&ndash;");
  595. _entityTable.Add(8212, "&mdash;");
  596. _entityTable.Add(8216, "&lsquo;");
  597. _entityTable.Add(8217, "&rsquo;");
  598. _entityTable.Add(8218, "&sbquo;");
  599. _entityTable.Add(8220, "&ldquo;");
  600. _entityTable.Add(8221, "&rdquo;");
  601. _entityTable.Add(8222, "&bdquo;");
  602. _entityTable.Add(8224, "&dagger;");
  603. _entityTable.Add(8225, "&Dagger;");
  604. _entityTable.Add(8240, "&permil;");
  605. _entityTable.Add(8249, "&lsaquo;");
  606. _entityTable.Add(8250, "&rsaquo;");
  607. _entityTable.Add(8364, "&euro;");
  608. }
  609. /// <summary>
  610. /// Converts US State Name to it's two-character abbreviation. Returns null if the state name was not found.
  611. /// </summary>
  612. /// <param name="stateName">US State Name (ie Texas)</param>
  613. /// <returns></returns>
  614. public static string USStateNameToAbbrev(string stateName)
  615. {
  616. stateName = stateName.ToUpper();
  617. foreach(KeyValuePair<string, string> key in _USStateTable)
  618. {
  619. if(stateName == key.Key)
  620. return key.Value;
  621. }
  622. return null;
  623. }
  624. /// <summary>
  625. /// Converts a two-character US State Abbreviation to it's official Name Returns null if the abbreviation was not found.
  626. /// </summary>
  627. /// <param name="stateAbbrev">US State Name (ie Texas)</param>
  628. /// <returns></returns>
  629. public static string USStateAbbrevToName(string stateAbbrev)
  630. {
  631. stateAbbrev = stateAbbrev.ToUpper();
  632. foreach(KeyValuePair<string, string> key in _USStateTable)
  633. {
  634. if(stateAbbrev == key.Value)
  635. return key.Key;
  636. }
  637. return null;
  638. }
  639. /// <summary>
  640. /// Fills the US States.
  641. /// </summary>
  642. private static void FillUSStates()
  643. {
  644. _USStateTable.Add("ALABAMA", "AL");
  645. _USStateTable.Add("ALASKA", "AK");
  646. _USStateTable.Add("AMERICAN SAMOA", "AS");
  647. _USStateTable.Add("ARIZONA ", "AZ");
  648. _USStateTable.Add("ARKANSAS", "AR");
  649. _USStateTable.Add("CALIFORNIA ", "CA");
  650. _USStateTable.Add("COLORADO ", "CO");
  651. _USStateTable.Add("CONNECTICUT", "CT");
  652. _USStateTable.Add("DELAWARE", "DE");
  653. _USStateTable.Add("DISTRICT OF COLUMBIA", "DC");
  654. _USStateTable.Add("FEDERATED STATES OF MICRONESIA", "FM");
  655. _USStateTable.Add("FLORIDA", "FL");
  656. _USStateTable.Add("GEORGIA", "GA");
  657. _USStateTable.Add("GUAM ", "GU");
  658. _USStateTable.Add("HAWAII", "HI");
  659. _USStateTable.Add("IDAHO", "ID");
  660. _USStateTable.Add("ILLINOIS", "IL");
  661. _USStateTable.Add("INDIANA", "IN");
  662. _USStateTable.Add("IOWA", "IA");
  663. _USStateTable.Add("KANSAS", "KS");
  664. _USStateTable.Add("KENTUCKY", "KY");
  665. _USStateTable.Add("LOUISIANA", "LA");
  666. _USStateTable.Add("MAINE", "ME");
  667. _USStateTable.Add("MARSHALL ISLANDS", "MH");
  668. _USStateTable.Add("MARYLAND", "MD");
  669. _USStateTable.Add("MASSACHUSETTS", "MA");
  670. _USStateTable.Add("MICHIGAN", "MI");
  671. _USStateTable.Add("MINNESOTA", "MN");
  672. _USStateTable.Add("MISSISSIPPI", "MS");
  673. _USStateTable.Add("MISSOURI", "MO");
  674. _USStateTable.Add("MONTANA", "MT");
  675. _USStateTable.Add("NEBRASKA", "NE");
  676. _USStateTable.Add("NEVADA", "NV");
  677. _USStateTable.Add("NEW HAMPSHIRE", "NH");
  678. _USStateTable.Add("NEW JERSEY", "NJ");
  679. _USStateTable.Add("NEW MEXICO", "NM");
  680. _USStateTable.Add("NEW YORK", "NY");
  681. _USStateTable.Add("NORTH CAROLINA", "NC");
  682. _USStateTable.Add("NORTH DAKOTA", "ND");
  683. _USStateTable.Add("NORTHERN MARIANA ISLANDS", "MP");
  684. _USStateTable.Add("OHIO", "OH");
  685. _USStateTable.Add("OKLAHOMA", "OK");
  686. _USStateTable.Add("OREGON", "OR");
  687. _USStateTable.Add("PALAU", "PW");
  688. _USStateTable.Add("PENNSYLVANIA", "PA");
  689. _USStateTable.Add("PUERTO RICO", "PR");
  690. _USStateTable.Add("RHODE ISLAND", "RI");
  691. _USStateTable.Add("SOUTH CAROLINA", "SC");
  692. _USStateTable.Add("SOUTH DAKOTA", "SD");
  693. _USStateTable.Add("TENNESSEE", "TN");
  694. _USStateTable.Add("TEXAS", "TX");
  695. _USStateTable.Add("UTAH", "UT");
  696. _USStateTable.Add("VERMONT", "VT");
  697. _USStateTable.Add("VIRGIN ISLANDS", "VI");
  698. _USStateTable.Add("VIRGINIA ", "VA");
  699. _USStateTable.Add("WASHINGTON", "WA");
  700. _USStateTable.Add("WEST VIRGINIA", "WV");
  701. _USStateTable.Add("WISCONSIN", "WI");
  702. _USStateTable.Add("WYOMING", "WY");
  703. }
  704. [Obsolete("Will be removed in future versions. Use Validation.IsAlpha instead")]
  705. public static bool IsAlpha(string s)
  706. {
  707. return Validation.IsAlpha(s);
  708. }
  709. [Obsolete("Will be removed in future versions. Use Validation.IsAlphaNumeric instead")]
  710. public static bool IsAlphaNumeric(string s)
  711. {
  712. return Validation.IsAlphaNumeric(s);
  713. }
  714. }
  715. }