45 lines
1.1 KiB
C#
45 lines
1.1 KiB
C#
![]() |
using System;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Text.RegularExpressions;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace Epost.Common
|
|||
|
{
|
|||
|
public class ConvertHexHelper
|
|||
|
{
|
|||
|
|
|||
|
public static string ConvertString(string value, int fromBase, int toBase)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
int intValue = Convert.ToInt32(value, fromBase);
|
|||
|
return Convert.ToString(intValue, toBase).ToUpper();
|
|||
|
}
|
|||
|
catch (Exception e)
|
|||
|
{
|
|||
|
LogHelper.WriteLogInfo("转换进制报错:"+e.Message+"初始值:"+value);
|
|||
|
//throw;
|
|||
|
return value;
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
/// <summary>
|
|||
|
/// 验证字符串是否是数字
|
|||
|
/// </summary>
|
|||
|
/// <param name="str"></param>
|
|||
|
/// <returns></returns>
|
|||
|
public static bool IsNum(string str)
|
|||
|
{
|
|||
|
Regex r = new Regex(@"^[+-]?\d*(,\d{3})*(\.\d+)?$");
|
|||
|
if (r.IsMatch(str))
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|