• 20150914 异常语句 math的方法 去空格 索引


    异常语句

    int cuo = 0;
    Console.WriteLine("请输入:");
    string s = Console.ReadLine();
    try
    {
    DateTime dt = DateTime.Parse(s);
    }
    catch (Exception ex)
    {
    Console.WriteLine("不是");
    cuo = 1;
    }
    if (cuo == 0)
    {
    Console.WriteLine("正确");
    }

    math的方法

    int i = Math.Abs(-5);//取绝对值
    Console.WriteLine(i);
    double a = Math.Ceiling(1.1);//天花板
    Console.WriteLine(a);
    Math.Floor(1.9);//下限
    Console.WriteLine(Math.PI);//圆周率
    Console.WriteLine(Math.Round(1.51));//四舍五入
    Console.WriteLine( Math.Pow(2,3));//幂次方
    Console.WriteLine(Math.Sqrt(16));//平方根

    //string a = "a aaa";
    //int changdu= a.Length; //返回字符串的长度
    ////Console.WriteLine(changdu);//显示长度

    //a = a.Trim();//去除全部空格返回一个新的值赋给a

    //a.TrimStart(); //去除前面的空格
    //a.TrimEnd();//去除后面的空格
    //a.ToLower();//转换成小写
    //a.ToUpper();//转换为大写

    /截取字符串。 字符串是由索引的,索引是从0开始

    //string js = "abcdeffdsfdsfaef";
    //string jiequ = js.Substring(2, 2);
    ////Console.WriteLine(jiequ);

    ////查询索引 indexof lastinddexof replace split
    //int id = js.IndexOf("ef",5); //查第一个ef在第几位
    //Console.WriteLine(id);
    //int lid = js.LastIndexOf("ef");//查最后一个ef在第几位
    //Console.WriteLine(lid);

    ////替换
    //string newjs = js.Replace("ef", "123");
    //Console.WriteLine(newjs); //原来的字符串没有变,是获得一个新的字符
    //Console.WriteLine(js);


    //分割
    //string xuanze = "a|b|c|d";
    //string[] newxuanze = xuanze.Split('|');

    //Console.WriteLine(newxuanze[0]); //输出结果为a,因为a为第一个字符
    //Console.WriteLine(newxuanze[2]);//输出结果为c,因为c是第三个字符

  • 相关阅读:
    还不懂mock测试?一篇文章带你熟悉mock
    android studio历史版本
    文档04_webfrom
    LeetCode 1763. Longest Nice Substring
    LeetCode 2006. Count Number of Pairs With Absolute Difference K
    LeetCode 539. Minimum Time Difference
    LeetCode 2000. Reverse Prefix of Word
    LeetCode 747. Largest Number At Least Twice of Others
    行为面试技巧之 STAR 法则 All In One
    LeetCode 字符串相乘算法题解 All In One
  • 原文地址:https://www.cnblogs.com/hz1234/p/4828163.html
Copyright © 2020-2023  润新知