3 Star 21 Fork 12

LinYong/多功能通信工具

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
StringExtension.cs 1.31 KB
一键复制 编辑 原始数据 按行查看 历史
LinYong 提交于 12个月前 . Socket完成
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CommunicationTools.Helper
{
//扩展方法的编写
public static class StringExtension
{
public static bool CheckEditRecLog = true;
public static string FormatStringLog(this string msg)
{
if (CheckEditRecLog)
{
return "[" + DateTime.Now + "]" + Environment.NewLine + msg + Environment.NewLine + Environment.NewLine;
}
else
{
return msg + Environment.NewLine + Environment.NewLine;
}
}
public static string StringToHexString(this string _str, Encoding encode)
{
//去掉空格
_str = _str.Replace(" ", "");
//将字符串转换成字节数组。
byte[] buffer = encode.GetBytes(_str);
//定义一个string类型的变量,用于存储转换后的值。
string result = string.Empty;
for (int i = 0; i < buffer.Length; i++)
{
//将每一个字节数组转换成16进制的字符串,以空格相隔开。
result += " " + Convert.ToString(buffer[i], 16);
}
return result;
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/sdfafdsafasdf/Communication-Tools.git
git@gitee.com:sdfafdsafasdf/Communication-Tools.git
sdfafdsafasdf
Communication-Tools
多功能通信工具
master

搜索帮助