• 【原创】-- C# 点滴积累 -- String


    索引:

    目录索引

    一、string.Format()

      将【数字字符串】转为两位小数显示的字符串:

    1                 dt = dtResult.Select(it => new CommodityPriceLimitEntity
    2                 {
    3                     CommodityId = it.CommodityId.ToString(),
    4                     CommodityName = it.CommodityName.ToString(),
    5                     CommodityCode = it.CommodityCode.ToString(),
    6                     Price = string.Format("{0:F2}", it.Price)
    7                 }).ToList();
    C# code

    ------------------------------------------------------------------------------------------------------------------------------

    ------------------------------------------------------------------------------------------------------------------------------

    ------------------------------------------------------------------------------------------------------------------------------

      方法一:将时间转为【yyyy/MM/dd HH:mm:ss】 格式显示字符串:

    1                     if (!string.IsNullOrWhiteSpace(item.EffectiveTimeEnd))  // 生效结束时间 
    2                     {
    3                         item.EffectiveTimeEnd = string.Format("{0}", item.EffectiveTimeEnd);
    4                     }
    C# code

    ------------------------------------------------------------------------------------------------------------------------------

    ------------------------------------------------------------------------------------------------------------------------------

      方法二:将时间转为【yyyy/MM/dd HH:mm:ss】 格式显示字符串: 

     1                         //
     2                         mb.CommodityCode = ma.CommodityCode;
     3                         mb.MaxPrice = ma.MaxPrice.ToString(".00");
     4                         mb.MinPrice = ma.MinPrice.ToString(".00");
     5                         mb.PriceLimitStart = string.Format(ma.EffectiveTimeStart.ToString(), "yyyy-MM-dd HH:mm:ss");
     6                         mb.PriceLimitEnd = string.Format(ma.EffectiveTimeEnd.ToString(), "yyyy-MM-dd HH:mm:ss");
     7 
     8                         //
     9                         result.Add(mb);
    10                     }
    11                 }
    C# code

    ------------------------------------------------------------------------------------------------------------------------------

    ------------------------------------------------------------------------------------------------------------------------------

    二、.ToString()

      将【数字字符串】转为两位小数显示的字符串:

    1             if (dt != null
    2                 && dt.Count > 0)
    3             {
    4                 foreach (var item in dt)
    5                 {
    6                     item.StandardPrice = Convert.ToDecimal(item.StandardPrice).ToString(".00");
    7                     item.MinPrice = Convert.ToDecimal(item.MinPrice).ToString(".00");
    8                 }
    9             }
    C# code

    ------------------------------------------------------------------------------------------------------------------------------

    ------------------------------------------------------------------------------------------------------------------------------

      便捷避免【字符串空引用】.ToString()

     1             result = result.Select(it => new ChannelCommodityPriceSearchResultDTO
     2             {
     3                 CompanyId = it.CompanyId.ToString(),
     4                 CompanyName = it.CompanyName.ToString(),
     5                 CommodityPriceId = it.CommodityPriceId.ToString(),
     6                 FirstChannelName = it.FirstChannelName.ToString(),
     7                 SecondChannelID = it.SecondChannelID.ToString(),
     8                 SecondChannelName = it.SecondChannelName.ToString(),
     9                 CommodityCode = it.CommodityCode.ToString(),
    10                 CommodityName = it.CommodityName.ToString(),
    11                 MainCommodityCode = it.MainCommodityCode.ToString(),
    12                 GlobalCategoryName = it.GlobalCategoryName.ToString(),
    13                 MainCategoryName = it.MainCategoryName.ToString(),
    14                 SubCategoryName = it.SubCategoryName.ToString(),
    15                 SubCategoryID = (it.SubCategoryID ?? "").ToString(),
    16                 Price = it.Price.ToString()
    17             }).ToList();
    C# code

    ------------------------------------------------------------------------------------------------------------------------------

    ------------------------------------------------------------------------------------------------------------------------------

    持续更新中~~

                                             蒙

                                        2017-08-03 13:58 周四

                                        2017-08-11  04:45 周五  更新于深夜系统发布过程中~~

                                        2017-08-17  09:35 周四  

  • 相关阅读:
    Pycharm软件更换pip默认安装源为国内安装源
    电商网站名词item>SKU与SPU
    Linux通过端口号查看使用进程结束进程
    window系统下的pycharm对虚拟机中的Ubuntu系统操作MySQL数据库
    JAVA项目常用的异常处理情况总结
    公文流转系统(未完成)
    《程序员修炼之道》读后感(三)
    Java文件操作递归遍历文件目录
    Java Web初试连接数据库完成学生信息录入
    JavaJFrame窗口实现新课程添加
  • 原文地址:https://www.cnblogs.com/Meng-NET/p/7279375.html
Copyright © 2020-2023  润新知