PKHeX/PKHeX.Core/Util/StringUtil.cs

37 lines
1.1 KiB
C#
Raw Normal View History

2016-07-09 22:30:12 +00:00
using System;
using System.Linq;
namespace PKHeX.Core
2016-07-09 22:30:12 +00:00
{
public partial class Util
{
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
}
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
}
public static uint GetHexValue(string s)
2016-07-09 22:30:12 +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
}
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
}
public static string ToTitleCase(string s)
{
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
}
}