Untitled - MARKUP 0.80 KB
                                
                                    using System;
using System.Text.RegularExpressions;

class Program
{
    static void Main()
    {
        string input = "To jest przykładowy tekst 12345 z liczbami.";
        string result = AddLinkToFirstNumber(input);
        Console.WriteLine(result);
    }

    static string AddLinkToFirstNumber(string input)
    {
        if (string.IsNullOrEmpty(input))
            return input;

        // Znajduje pierwszy ciąg cyfr
        Match match = Regex.Match(input, @"\d+");
        if (match.Success)
        {
            string number = match.Value;
            string link = $"<a href='https://example.com/{number}'>{number}</a>";
            return input.Replace(number, link, 1);
        }

        return input;
    }
}
                                
                            

Paste Hosted With By Wklejamy.pl