2016-07-09 22:30:12 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.Core
|
2016-07-09 22:30:12 +00:00
|
|
|
|
{
|
|
|
|
|
public partial class Util
|
|
|
|
|
{
|
2017-01-08 07:54:09 +00:00
|
|
|
|
public static int ToInt32(string value)
|
2016-07-09 22:30:12 +00:00
|
|
|
|
{
|
|
|
|
|
string val = value?.Replace(" ", "").Replace("_", "").Trim();
|
2016-07-22 05:45:20 +00:00
|
|
|
|
return string.IsNullOrWhiteSpace(val) ? 0 : int.Parse(val);
|
2016-07-09 22:30:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
public static uint ToUInt32(string value)
|
2016-07-09 22:30:12 +00:00
|
|
|
|
{
|
|
|
|
|
string val = value?.Replace(" ", "").Replace("_", "").Trim();
|
2016-07-22 05:45:20 +00:00
|
|
|
|
return string.IsNullOrWhiteSpace(val) ? 0 : uint.Parse(val);
|
2016-07-09 22:30:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static uint GetHexValue(string s)
|
2016-07-09 22:30:12 +00:00
|
|
|
|
{
|
2017-06-18 01:37:19 +00:00
|
|
|
|
string str = GetOnlyHex(s);
|
2016-07-22 05:45:20 +00:00
|
|
|
|
return string.IsNullOrWhiteSpace(str) ? 0 : Convert.ToUInt32(str, 16);
|
2016-07-09 22:30:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static string GetOnlyHex(string s)
|
2016-07-09 22:30:12 +00:00
|
|
|
|
{
|
2016-07-22 05:45:20 +00:00
|
|
|
|
return string.IsNullOrWhiteSpace(s) ? "0" : s.Select(char.ToUpper).Where("0123456789ABCDEF".Contains).Aggregate("", (str, c) => str + c);
|
2016-07-09 22:30:12 +00:00
|
|
|
|
}
|
2017-05-12 04:34:18 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
public static string ToTitleCase(string s)
|
2017-05-12 04:34:18 +00:00
|
|
|
|
{
|
|
|
|
|
return string.Join(" ", s.Split(' ').Select(x => x[0].ToString().ToUpper() + x.Substring(1, x.Length - 1).ToLower()));
|
|
|
|
|
}
|
2016-07-09 22:30:12 +00:00
|
|
|
|
}
|
|
|
|
|
}
|