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;
// Znalezienie pierwszego ciągu cyfr
Match match = Regex.Match(input, @"\d+");
if (match.Success)
{
string number = match.Value;
string link = string.Format("<a href='https://example.com/{0}'>{0}</a>", number);
// Ręczna zamiana pierwszego wystąpienia liczby
int index = input.IndexOf(number);
if (index != -1)
{
return input.Substring(0, index) + link + input.Substring(index + number.Length);
}
}
return input;
}
}
Paste Hosted With By Wklejamy.pl