zoukankan      html  css  js  c++  java
  • C# string 中的 @ 作用处理\等字符

    C# 字符串前的 @什么意思: string
    sqlStr = @"select count(*) as Total from [PCS_OfferPriceBills] ";

    C# 字符串前的 @什么意思: string sqlStr = @"select count(*) as Total from [PCS_OfferPriceBills] "; sqlStr = sqlStr + " where " + @strWhere;
    不转移字符当做字符串处理。 如string ss = @"aa\naa";输出 aa\naa; 而string ss = "aa\naa";输出 aa aa
     

    C# string 字符串的前面可以加 @(称作“逐字字符串”)将转义字符(\)当作普通字符对待,比如:

    string str = @"C:\Windows";

    如果我们去掉 @ 的话,应该是:

    string str = "C:\\Windows";

    @ 字符串中,我们用两个连续英文双引号表示一个英文双引号,如下字符串的实际内容为:="=,字符串长度为 3。

    string str = @"=""=";

    @ 字符串中可以任意换行,换行符及缩进空格都计算在字符串长度之内。

    string str = @"<script type=""text/javascript"">
        <!--
        -->
        </script>";

    由于 @ 的这种特性,我们常将其应用到 SQL 字符串中。

    string sql = @"select * from tbl";

    @ 只在连续一段字符串中有效,@"abc" + "\\",用 + 将两个字符串连接起来,第二个字符串中没有用 @ 标识,其中的 \ 就成为转义字符。

  • 相关阅读:
    .NET开发相关使用工具和框架
    Jquery.KinSlideshow 焦点图标轮换
    可能发生了架构损坏。请运行 DBCC CHECKCATALOG。
    mssql使用问题大合集
    做饭流程js
    点击导航切换和隐藏
    批量修改文件名后缀
    GB2312转码utf-8字符方法
    border三角形的3种方式
    移动端nav导航栏
  • 原文地址:https://www.cnblogs.com/wangyt223/p/2716056.html
Copyright © 2011-2022 走看看