• 15-07-06 类


    String类

    string a = "abcdef123456";

    a.Length;     是一个属性,代表字符串的长度 ★
    a[2];     a代表字符串中a打头,2代表在字符串中的位置,从0开始数,[]是索引号,a[2]输出结果是c

    a=a.Trim();     去除左右两边的空格 ★
    a=a.TrimStart();     去掉左边的空格
    a=a.TrimEnd();     去掉右边的空格


    a=a.ToLower();     将字符串中的大写英文字符转化成小写
    a=a.ToUpper();     将字符串中的小写英文字符转化成大写

    a=a.StartsWith("a");     匹配开头,看是不是以a开头,返回true或false
    a=a.EndsWith("6");     匹配结尾,看是不是以6结尾,返回true或false
    a=a.Contains("cd");     匹配整个字符串中是否包含cd,返回true或false ★

    a=a.IndexOf("1");     某字符串在str里面哪个位置出现(第一次出现的位置)
    a=a.LastIndexOf("2"):     某字符串在str里面最后一次出现的位置

    a=a.Substring(5,4);     截取字符串 从第五位开始截取字符串,截取4位 ★

    a=a.Replace("cd","gg");     替换所有符合指定段的字符串条件的字符串(查找替换功能),将字符串中的cd替换为gg

    Math类:

    double n = 3.1415;
    Math.Round(n,2);     将n四舍五入,小数点后保留2位
    Math.Ceiling(n);     取大于该小数的最小整数
    Math.Floor(n);     取小于该小数的最大整数
    Math.Sqrt(a);     开平方,平方根
    Math.Pow(2,4);     求2的4次方

    DateTime类:

    DateTime d =DateTime.Now     电脑当前时间
    int a = d.Year;     提取年份
    int b = d.Month;     提取月份
    int c = d.Day;    提取日期
    int e = d.Hour;     提取小时
    int f = d.Minute;     提取分钟
    int g = d.Second;     提取秒
    int h = d.Millisecond;     提取毫秒
    int k = d.DayOfYear;     获取日期是该年中第几天
    DayOfWeek l = d.DayOfWeek;     该日期是一周中的周几

    System.TimeSpan da = new TimeSpan(1,0,0,0);
    d = d.Add(da);

    d = d.AddYears(1);     添加一年
    d = d.AddMouth(1);     添加一个月
    d = d.AddDay(1);     添加一天
    d = d.AddHour(1);     添加一小时
    d = d.AddMinute(1);     添加一分钟
    d = d.AddSeconds(1);     添加一秒钟

    ToString("yyyy年MM月dd日 hh时mm分ss秒") 按”年月日时分秒“表示出来

    例:输入身份证号查出生日期

                Console.WriteLine("请输入身份证号:");
                string code = Console.ReadLine();
    
                string nian = code.Substring(6, 4);
                string yue = code.Substring(10,2);
                string ri = code.Substring(12,2);
                Console.WriteLine("你的出生日期为:{0}年{1}月{2}日",nian,yue,ri);
  • 相关阅读:
    IB(InterBase Server) 的完整连接格式
    jna
    编写基于Prototype的Javascript动画类
    Go——使用 go mod ——有依赖的Go工程
    pkgconfig—— PKG_CONFIG_PATH——Makefile——pkgconfig的作用与使用
    Go——Goland Debug报错Version of Delve is too old for this version of Go
    NATS——NATS Streaming 是什么 (转)
    Go——Go语言调用C语言
    go get安装包超时处理
    NATS—基础介绍 (转自 https://www.cnblogs.com/yorkyang/p/8392172.html)
  • 原文地址:https://www.cnblogs.com/jia520110270/p/4628750.html
Copyright © 2020-2023  润新知