You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.8 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace Shentun.Utilities
  5. {
  6. public static class StringExtr
  7. {
  8. public static decimal ToDecimal( string value)
  9. {
  10. decimal data = 0.0m;
  11. if (value.ToUpper().Contains("E"))
  12. {
  13. data = Convert.ToDecimal(Decimal.Parse(value.ToString(), System.Globalization.NumberStyles.Float));
  14. }
  15. else
  16. {
  17. data = Convert.ToDecimal(value);
  18. }
  19. return data;
  20. }
  21. public static string GetKeyValue(string source,string keyword,string separator,string defaultValue)
  22. {
  23. if(string.IsNullOrWhiteSpace(source)|| string.IsNullOrWhiteSpace(keyword) || string.IsNullOrWhiteSpace(separator))
  24. {
  25. return defaultValue;
  26. }
  27. source = source.Replace(" ", "");
  28. var values = source.Split(separator);
  29. keyword = keyword.Trim() + "=";
  30. foreach (var item in values)
  31. {
  32. if (item.StartsWith(keyword))
  33. {
  34. var value = item.Substring(keyword.Length).Trim();
  35. if (string.IsNullOrWhiteSpace(value))
  36. {
  37. return defaultValue;
  38. }
  39. return value;
  40. }
  41. }
  42. return defaultValue;
  43. }
  44. public static string GetKeyValue(string source, string keyword, string separator)
  45. {
  46. return GetKeyValue(source, keyword, separator, "");
  47. }
  48. public static string GetKeyValue(string source, string keyword)
  49. {
  50. return GetKeyValue(source, keyword, ";");
  51. }
  52. }
  53. }