Any Effective C# Spintax Code ?

Veron1ka

Newbie
Joined
May 22, 2011
Messages
39
Reaction score
4
I am looking for someone who is experienced with Spintax and can provide me or point me to a performant nested spintax code in C#, I found many ready made codes online but they are either slow when they retrun result or they are not multi levels deep :bee2:

Thanks :)
 
I've been using this code for a long time, but not very sure about the performance hiccups as it's not used very extensively.

private string GetSpintax(Random rnd, string inStr)
{
string ptrn = "{[^{}]*}";
Match mt = Regex.Match(inStr, ptrn);
while (mt.Success)
{
string seg = inStr.Substring(mt.Index + 1, mt.Length - 2);
string[] choices = seg.Split('|');
inStr = inStr.Substring(0, mt.Index) + choices[rnd.Next(choices.Length)] + inStr.Substring(mt.Index + mt.Length);
mt = Regex.Match(inStr, ptrn);
}


return inStr;
}
 
Back
Top