【C#】不采用正则而是用IndexOf和Substring提取指定内容
|
admin
2025年2月14日 17:45
本文热度 515
|
:【C#】不采用正则而是用IndexOf和Substring提取指定内容
// 定义变量存储最新登录信息
string latestLoginUser = string.Empty;
// 解析用户信息,这里简单地从消息中提取用户名
// 不同系统的事件消息格式可能略有不同,需根据实际情况调整解析逻辑
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();
}
该文章在 2025/2/14 17:45:17 编辑过