Split de un texto a partir de fecha

閲覧: 7 回
最初の未読メッセージにスキップ

Carlos Admirador

未読、
2021/06/23 16:32:012021/06/23
To: AltNet-Hispano
Tengo un texto así:

2021-06-22 09:21:24 - marking abandoned based on notes below 2021-06-22 13:11:41 - think the thid is string/SG 2021-06-23 19:21:11 - texto

Cómo hacer un split del texto por las fechas ?

Quedaría así:

2021-06-22 09:21:24 - marking abandoned based on notes below 
2021-06-22 13:11:41 - think the thid is string/SG 
2021-06-23 19:21:11 - texto

Carlos Admirador

未読、
2021/06/24 16:28:302021/06/24
To: AltNet-Hispano

una solución rápida, pero depende (performance/precisión de validacion de la fecha, legibilidad) haría q cambie la solución

static string SplitAsStringFromDates(string text)
{
var matches = Regex.Matches(text, @"[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}", RegexOptions.Compiled);
 var sb = new StringBuilder();
Match matched = null;
for (int i = 0; i < matches.Count; i++)
{
matched = matches[i];
if (i == matches.Count - 1)
sb.AppendLine(text.Substring(matched.Index));
else
sb.AppendLine(text.Substring(matched.Index, matches[i + 1].Index - matched.Index));
}
return sb.ToString();
}


全員に返信
投稿者に返信
転送
新着メール 0 件