“hello $world”的格式化字符串是指把字符串中一个单词,以一个标示开头。可以代换为单词所指的变量。
这个在jq有,而C#string的格式只能用格式的字符占位符,格式的字符占位符都是数字,这样多了很容易混,好多我都出现了,拷贝代码,然后没有排好数字,漏了一个数字,这样出现了错误。
string.Format("这里有很长字符串{0}{2}" , "Hello" , "csdn");
C# 6.0 $"Hello {csdn}"
而看到一个大神实现了类似jQueryStringFormat的扩展string,觉得C#内置有一个方法:

            var csdn = "csdn";
            var result = $"Hello {csdn}";
            Console.Write(result);

会输出C# 6.0 $"Hello {csdn}"

通过$开头字符串,中间{}作为变量名,可以把字符串代换为变量的字符。

代码:https://code.csdn.net/lindexi_gd/lindexi_gd/tree/master/hellow_$csdn

参考:http://www.cnblogs.com/isaboy/p/4945045.html

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-30
  • 2021-10-11
  • 2021-07-30
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
猜你喜欢
  • 2021-06-26
  • 2022-12-23
  • 2021-06-20
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案