:【C#】不采用正則而是用IndexOf和Substring提取指定內(nèi)容
// 定義變量存儲最新登錄信息 string latestLoginUser = string.Empty; // 解析用戶信息,這里簡單地從消息中提取用戶名 // 不同系統(tǒng)的事件消息格式可能略有不同,需根據(jù)實際情況調(diào)整解析邏輯 string message = entry.Message; int startIndex = message.IndexOf("user name: ") + "user name: ".Length; int endIndex = message.IndexOf(Environment.NewLine, startIndex); if (startIndex > 0 && endIndex > startIndex) { latestLoginUser = message.Substring(startIndex, endIndex - startIndex).Trim(); }
// 定義變量存儲最新登錄信息
string latestLoginUser = string.Empty;
// 解析用戶信息,這里簡單地從消息中提取用戶名
// 不同系統(tǒng)的事件消息格式可能略有不同,需根據(jù)實際情況調(diào)整解析邏輯
string message = entry.Message;
int startIndex = message.IndexOf("user name: ") + "user name: ".Length;
int endIndex = message.IndexOf(Environment.NewLine, startIndex);
if (startIndex > 0 && endIndex > startIndex)
{
latestLoginUser = message.Substring(startIndex, endIndex - startIndex).Trim();
}