using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CrazyStudio.Core.Common.Tools
{
    public static class StringTool
    {
        public static string ConvertTF(string str)
        {
            if (string.IsNullOrEmpty(str))
            {
                return str;
            }
            string[] strItems = str.Split('_');
            string strItemTarget = string.Empty;
            if (strItems.Length > 1)
            {
                if (strItems[0].Length > 0)
                {
                    strItemTarget = strItems[0][0].ToString().ToUpper();
                    if (strItems[0].Length > 1)
                    {
                        strItemTarget += strItems[0].ToString().Substring(1);
                    }
                }
                for (int j = 1; j < strItems.Length; j++)
                {
                    string temp = strItems[j].ToString();
                    string temp1 = temp[0].ToString().ToUpper();
                    string temp2 = "";
                    temp2 = temp1 + temp.Remove(0, 1);
                    strItemTarget += temp2;
                }
                return strItemTarget;
            }
            else
            {
                if (str.Length > 1)
                {
                    strItemTarget = str[0].ToString().ToUpper() + str.Substring(1);
                }
                else
                {
                    strItemTarget = str[0].ToString().ToUpper();
                }
                return strItemTarget;
            }
        }

        /// <summary>
        /// 16进制转普通字符串(带汉字)
        /// </summary>
        /// <returns></returns>
        public static string GetHexDecodeText(string hexData)
        {
            List<byte> byList = new List<byte>();//实例化list

            while (hexData != "" && hexData != " ")//先判断字符串是否查询结束
            {
                if (hexData.Substring(0, 1) == " ")//判断第一个字符是否为空格
                {
                    hexData = hexData.Substring(1, hexData.Length - 1);//去掉第一个空格
                }
                int y = hexData.IndexOf(" ");//查询第一个空格的索引在哪

                byList.Add(Convert.ToByte(hexData.Substring(0, y), 16));//将空格前的所有字符转换成ASCII字节数组全部添加进来

                int x = hexData.Length;//计算str字符串长度

                hexData = hexData.Substring(y, x - y);//截取空格后面剩下的字符串
            }
            byte[] byArray = byList.ToArray();//list转化为byte数组

            string data = Encoding.Default.GetString(byArray);//byee数组直接转化为字符串

            return data;
        }
    }
}

