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.
|
|
using System;using System.Collections.Generic;using System.Text;
namespace Shentun.Utilities{ public static class StringExtr { public static decimal ToDecimal( string value) { decimal data = 0.0m; if (value.ToUpper().Contains("E")) { data = Convert.ToDecimal(Decimal.Parse(value.ToString(), System.Globalization.NumberStyles.Float)); } else { data = Convert.ToDecimal(value); }
return data; }
public static string GetKeyValue(string source,string keyword,string separator,string defaultValue) { if(string.IsNullOrWhiteSpace(source)|| string.IsNullOrWhiteSpace(keyword) || string.IsNullOrWhiteSpace(separator)) { return defaultValue; } source = source.Replace(" ", ""); var values = source.Split(separator);
keyword = keyword.Trim() + "=";
foreach (var item in values) { if (item.StartsWith(keyword)) { var value = item.Substring(keyword.Length).Trim(); if (string.IsNullOrWhiteSpace(value)) { return defaultValue; } return value; } } return defaultValue;
}
public static string GetKeyValue(string source, string keyword, string separator) { return GetKeyValue(source, keyword, separator, "");
}
public static string GetKeyValue(string source, string keyword) { return GetKeyValue(source, keyword, ";");
} }}
|