jquery怎么获取c#string.format 的值

如题所述

可以仿照jQuery中的选择器方法,用作为变量前缀。例如Ilove$something中的作为变量前缀。例如Ilove$something中的someting就是变量,可以将something变量的值替换到字符串中。
1 //模板字符串前缀
2 private static readonly string __prefix = "$";
3 // $ 正则表达式 $name
4 private static readonly Regex VariableRegex = new Regex(@"\$(@{0,1}[a-zA-Z_\.0-9]+)");
5
上面定义了变量的规则,必须是$打头的有效变量,下面将字符串用该正则表达式进行捕获

1 private static IEnumerable<string> GetEnumerateVariables(string s)
2 {
3 var matchCollection = VariableRegex.Matches(s);
4
5 for (int i = 0; i < matchCollection.Count; i++)
6 {
7 yield return matchCollection[i].Groups[1].Value;
8 }
9 }
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答