What i'm trying to do is insert a string <a href=\"{href}\">{text}</a> in a larger wall of article text but the large wall of text looks like:
{word|word|word} {word|word|word} {word|word|word} {word|word|word|word} etc
I'm looking to insert <a href=\"{href}\">{text}</a>"; randomly, but it has to be between one of these } { curly brackets so it will look like } <a href=\"{href}\">{text}</a> {
The way my code is now it just inserts anywhere (i know i need to add the logic to look between the brackets) which is where my issue is, i'm not sure the best way to do this.
Code:
public static string GetAndInjectAhrefLinkIntoArticle(string article, string href, string text) {
string injectedArticle = null;
try {
var rnd = new Random();
string stringToInsert = $"<a href=\"{href}\">{text}</a>";
int length = article.Length;
if (length > 0)
{
int pos = rnd.Next(0, length);
injectedArticle = article.Insert(pos, stringToInsert);
}
}
catch (Exception ex)
{
DebugLogging($"[{DateTime.Now}]-[{ex}]");
}
return injectedArticle;
}
Any help would be appreciated.