PKHeX/Util/StringUtil.cs

32 lines
951 B
C#
Raw Normal View History

2016-07-09 22:30:12 +00:00
using System;
using System.Linq;
namespace PKHeX
{
public partial class Util
{
internal static int ToInt32(string value)
{
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
}
internal static uint ToUInt32(string value)
{
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
}
internal static uint getHEXval(string s)
{
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
}
internal static string getOnlyHex(string s)
{
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
}
}
}