網站首頁 編程語言 正文
Dictionary<string, string>拆分字符串
private Dictionary<string, string> GenDictionary(byte[] inMsg)
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
string arg= Encoding.Default.GetString(inMsg);
char[] trimChars = new char[1];
string text = arg.TrimEnd(trimChars);
string[] array = text.Split(new char[]
{
';'
});
for (int i = 0; i < array.Length; i++)
{
string text2 = array[i];
if (!string.IsNullOrEmpty(text2) && !dictionary.ContainsKey(text2.Split(new char[]
{
':'
})[0]))
{
dictionary.Add(text2.Split(new char[]
{
':'
})[0], text2.Replace(text2.Split(new char[]
{
':'
})[0] + ":", ""));
}
}
return dictionary;
}
記錄log的方法
public static void WriteLog(string strLog)
{
string pathName = Environment.CurrentDirectory + "\\LOG\\" + DateTime.Now.ToString("yyyyMMdd");
string FileName = "Execute.log";
FileName = pathName + "\\" + FileName;
if (!Directory.Exists(pathName))
{
Directory.CreateDirectory(pathName);
}
FileStream fileStream = null;
StreamWriter streamWriter = null;
try
{
if (File.Exists(FileName))
{
//追加記錄內容
fileStream = new FileStream(FileName, FileMode.Append, FileAccess.Write);
}
else
{
//新建文件并記錄
fileStream = new FileStream(FileName, FileMode.Create, FileAccess.Write);
}
streamWriter = new StreamWriter(fileStream);
streamWriter.WriteLine("【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "】" + strLog);
}
finally
{
streamWriter.Close();
fileStream.Close();
}
}
原文鏈接:https://www.cnblogs.com/wml-it/p/15618324.html
相關推薦
- 2022-07-22 SpringBoot允許跨域訪問配置
- 2022-06-15 python中?conda?虛擬環境管理和jupyter內核管理_python
- 2023-02-14 詳解C/C++?Linux出錯處理函數(strerror與perror)的使用_C 語言
- 2022-11-15 python列表中常見的一些排序方法_python
- 2022-05-10 SpringBoot端口已占用解決:配置端口號
- 2023-04-18 Python之split函數的深入理解_python
- 2022-10-18 ASP.NET?MVC增加一條記錄同時添加N條集合屬性所對應的個體_實用技巧
- 2022-04-27 幾個關于python??Pdf?技巧的分享_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支