我上了这门课,是用来做旋转文字的。
public class Spinner
{
private static Random rnd = new Random();
public static string Spin(string str)
{
string regex = @"\{(.*?)\}";
return Regex.Replace(str, regex, new MatchEvaluator(WordScrambler));
}
public static string WordScrambler(Match match)
{
string[] items = match.Value.Substring(1, match.Value.Length - 2).Split('|');
return items[rnd.Next(items.Length)];
}
}但我需要它能够旋转多旋量课文。
作为例子{1\2}-{3\4}
返回:2-4,所以它工作。
但是:{1\2}\{3\4}-{5~6}\{7\8}}
返回:2\x{5~4}-{5/7}
所以如果旋量税里面有旋量税,那就不起作用了。
有什么帮助吗?)
发布于 2014-01-17 13:24:15
正则表达式在dealing with nested structures中不是很好,这意味着您可能应该尝试另一种方法。
在您的示例中,{{1|2}|{3|4}} - {{5|6}|{7|8}}与{1|2|3|4} - {5|6|7|8}是相同的,因此您可能不需要嵌套的spintax。
https://stackoverflow.com/questions/21186616
复制相似问题