字符串转为十六进制表示的字符串:
/// <summary>
/// 此方法用于将普通字符串转换成16进制的字符串。
/// </summary>
/// <param name="_str">要转换的字符串。</param>
/// <returns></returns>
public string StringToGBKString(string _str)
{
string dt = "";
byte[] byStr = Encoding.GetEncoding("GB2312").GetBytes(_str);
foreach (var item in byStr)
{
dt += item.ToString("X2");
}
return dt;
}
private string GetStringFromAsciiHex(string input)
{
System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
string acc = "";
if (input.Length % 2 == 0)
{
byte[] bytes = new byte[input.Length / 2];
for (int i = 0; i < input.Length; i += 2)
{
string hex = input.Substring(i, 2);
bytes[i/2] = Convert.ToByte(hex, 16);
}
acc = asciiEncoding.GetString(bytes);
}
return acc;
}
字符串倒序方法:
string str= “12345”;
char[] ch = str.ToArray();//把文本框你的内容转换为char类型数组
Array.Reverse(ch, 0, str.Length);//使用Array类的Reverse方法颠倒数据
str2 = new StringBuilder().Append(ch).ToString();//获取指定数组
输出:
54321
第二种方法:
string res ="asd";
res=String.Join("-", res.Reverse());
//res = "d-s-a"