gpt-4-0314· OpenAI
WildChat-4.8M (AI2)
scrivi una funzione c# per estrarre tutti i GUID da una stringa usando le RegEx
- User
scrivi una funzione c# per estrarre tutti i GUID da una stringa usando le RegEx
- Assistant
Ecco una funzione C# che estrae tutti i GUID da una stringa utilizzando le espressioni regolari:
csharpusing System; using System.Collections.Generic; using System.Text.RegularExpressions; class Program { static void Main(string[] args) { string input = "Questo è un GUID: 070c5b60-92ab-4897-a111-309ea80f34d5 e un altro: 15aa6390-272c-4153-8c78-362efde42865."; var guids = ExtractGuids(input); foreach (var guid in guids) { Console.WriteLine(guid); } } static List<Guid> ExtractGuids(string input) { var regex = new Regex(@"\b[a-fA-F0-9]{8}(?:-[a-fA-F0-9]{4}){3}-[a-fA-F0-9]{12}\b"); var matches = regex.Matches(input); var guids = new List<Guid>(); foreach (Match match in matches) { guids.Add(Guid.Parse(match.Value)); } return guids; } }