string

(1)字符串.Length    Length作用于求字符串的长度,返回一个int值

(2)字符串.TrimStart();  TrimStart();可删除前空格,返回一个string类

(3)字符串.TrimEnd();   TrimEnd(); 可删除后空格,也返回一个string类

(4) ***字符串.Trim();      Trim(); 删除前后空格,返回string类

字母大小写:

(5)****字符串.ToUpper();  ToUpper();  将字符串大写,返回string类

(6)****字符串.ToLower();  ToLower( ); 将字符串小写,返回string类

截取:

(7)***字符串.SubString(a);  将字符串从下标a开始截取后面部分

(8)****字符串.SubString(a,b);  将字符串从下标a开始截取后面b个字符,返回string类

注意:下标索引从0开始

截取的对象下标、长度必须在字符串范围之内,否则报错。

索引:

(9)***字符串.IndexOf(“字符串a”);  从字符串中索引第一个字符串a,返回int值

(10)****字符串.IndexOf(“字符串a”,int b );  从b值开始索引字符串a, 返回int值

(11)***字符串.LastIndexOf(“字符串a”);  从最后开始索引,索引出最后一个字符串a,    返回int值

注意:如果字符串中不存在索引对象,则返回-1;

比较判断字符:

(12)***字符串.StartWidth("字符串a");  判断字符串是否以“字符串a”开头

(13)***字符串.EndsWidth("字符串b"); - 判断字符串是否以“字符串b”结尾

(14)**字符串.Contains("字符串c"); - 判断字符串是否包含“字符串c”,返回bool类

移除、替换:

(15)****变量.Replace(要替换的字符串a,替换成的字符串b);  字符替换  返回string类

(16)s.Remove(索引int值); 移除从索引到末尾的全部字符  返回string类

例:

Console.Write("请输入您的邮箱:");
string id = Console.ReadLine();
string end = "输入的邮箱正确";
bool mailonly = true;
bool mailonlyy = true;
bool mailstart = true;
bool mailend = true;
bool atyd = true;
bool atsd = true;
bool dianot = true;
bool dianno = true;
bool numno = true;
int s = id.Length; #region 有且只有一个@符号
int mailonly1 = id.IndexOf("@");
if (mailonly1 == -)
{
mailonlyy = false;
end = "输入的邮箱有误!";
}
else
{
string mailonly2 = id.Substring(mailonly1+);
int mailonly3 = mailonly2.IndexOf("@");
if (mailonly3 != -)
{
mailonly = false;
end = "输入的邮箱有误!";
}
}
#endregion #region 不能以@开头 bool mailstart1 = id.StartsWith("@");
if (mailstart1 == true)
{
mailstart = false;
end = "输入的邮箱有误!";
}
#endregion #region 不能以@结尾
bool mailend1 = id.EndsWith("@");
if (mailend1 == true)
{
mailend = false;
end = "输入的邮箱有误!";
}
#endregion #region@之后必须有点
if (mailonly1 != -)
{
string atyd1 = id.Substring(mailonly1);
int atyd2 = atyd1.IndexOf(".");
if (atyd2 == -)
{
atyd = false;
end = "输入的邮箱有误!";
}
}
else
{
end = "输入的邮箱有误!";
}
#endregion #region@之后不能是点
int atsd1 = id.IndexOf("@.");
if (atsd1 != -)
{
atsd = false;
end = "输入的邮箱有误!";
}
#endregion #region 最少一个点,最多两个点
for (; ; )
{
try
{
string atyd1 = id.Substring(mailonly1);
int dianot1 = atyd1.IndexOf(".");
int a = ;
if (dianot1 != -)
{
a++;
}
if (a > )
{
dianot = false;
end = "输入的邮箱有误!";
break;
}
else
{
break;
}
}
catch
{
end = "输入的邮箱有误!";
break;
}
}
#endregion #region 不能以点结尾 bool dianno1 = id.EndsWith(".");
if (dianno1 == true)
{
dianno = false;
end = "输入的邮箱有误!";
} #endregion #region 不能以数字结束 string numno1 = id.Substring(s-);
try
{
int numno2 = Convert.ToInt32(numno1);
bool b=Convert.ToBoolean(numno2);
if (b == true)
{
numno = false;
end = "输入的邮箱有误!";
}
}
catch
{
}
#endregion
if (mailonlyy == false)
{
Console.WriteLine("必须有@");
}
if (mailonly == false)
{
Console.WriteLine("只能有一个@符号");
}
if (mailstart == false)
{
Console.WriteLine("不能以@开头");
}
if (mailend == false)
{
Console.WriteLine("不能以@结尾");
}
if (atyd == false)
{
Console.WriteLine("@之后必须有点");
}
if (atsd == false)
{
Console.WriteLine("@之后不能是点");
}
if (dianot == false)
{
Console.WriteLine("最少一个点,最多两个点");
}
if (dianno==false)
{
Console.WriteLine("不能以点结束");
}
if (numno==false)
{
Console.WriteLine("不能以数字结束");
}
Console.WriteLine(end);
Console.ReadLine();

math

(1)Math.Pow(变量值x,幂y); 求变量值x的y幂次方;x,y为double类型,返回double类

(2)Math.Sqrt(变量值x);  求变量值x的平方根,返回double类

(3)Math.Ceiling(变量值x);   取变量值X(double类)上限

(4)Math.Floor(变量值x);    取变量值x(double类)下限

(5)Math.Round(变量值x);  四舍五入,当整数部分为奇数5入;当整数部分为奇数5舍

(6)Math.Abs(变量值x);     取变量值x的绝对值

三DateTime

(1)DateTime 变量名 = new DateTime(); - 定义变量类型

变量名 = DateTime.Now; - 获取此电脑当前时间

(2)变量.ToString("格式"); - 设置日期格式化

格式:yyyy-年 MM-月 dd-日 hh-12制小时 HH-24制小时 mm-分钟 ss-秒  ms-毫秒

(3)时间加

1、变量.AddYears(int值); - 在此时间基础上增加int值年

2、变量.AddMonths(int值); - 在此时间基础上增加int值月

3、变量.AddDays(int值); - 在此时间基础上增加int值日

4、变量.AddHours(); - 在此时间基础上增加int值小时

5、变量.AddMinutes(); - 在此时间基础上增加int值分钟

6、变量.AddSeconds(); - 在此时间基础上增加int值秒

(4)截取部分时间变量

1、时间变量.Year; - 获取此时间变量的年份

2、时间变量.Month; - 获取月份

3、时间变量.Day; - 日

4、时间变量.Hour; - 小时

5、时间变量.Minute; - 分钟

6、时间变量.Second; - 秒

7、时间变量.Millisecond; - 毫秒

5)获取变量天数、星期

1、时间变量.DayOfYear; - 获取当前日期是此年中的第几天

2、时间变量.DayOfWeek; - 获取是星期几

3、时间变量.TimeOfDay; - 获取时间部分

4、时间变量.Date; - 获取日期部分

(6)TimeSpan类型 - 时间间隔类型

1、时间变量.Days - 差距多少天

2、时间变量.Hours - 一天中差距多少小时

3、时间变量.Minutes - 一天中差距多少分钟

4、时间变量.Seconds - 一天中差距多少秒

5、时间变量.Milliseconds - 毫秒

6、时间变量.Total(Days、Hours、Minutes…)累计天、小时等差距

例:

Console.Write("请输入年:");
string year = Console.ReadLine();
Console.Write("请输入月:");
string month = Console.ReadLine();
Console.Write("请输入日:");
string day = Console.ReadLine();
string s = year + "/" + month + "/" + day;
try
{
DateTime dt = new DateTime();
dt = DateTime.Parse(s);
string a = dt.ToString("yyyy年MM月dd日");
int b = Convert.ToInt32(dt.DayOfWeek);
int c = dt.DayOfYear;
string x = "日一二三四五六";
string x1 = x.Substring(b, );
Console.WriteLine(a + "是此年的第" + c + "天,星期" + x1);
DateTime y = new DateTime(, , );
TimeSpan t = dt - y;
int t1 = Convert.ToInt32(t.Days);
int t2 = Math.Abs(t1);
if (t1 < )
{
Console.Write("距离2012年12月24日世界末日还有" + t2 + "天");
}
else if (t1 > )
{
Console.Write("世界末日过去了" + t1 + "天");
}
else
{
Console.Write("您输入的是世界末日!!!");
} }
catch
{
Console.WriteLine("输入的时间日期有误!");
} Console.ReadLine();

【2-26】string/math/datetime类的定义及其应用的更多相关文章

  1. 类之string类、Math类、DateTime类

    String类 string a = "abcdef123456"; 注:字符串的长度是从0开始计数的如:0,1,2,3,4,5,6,7,8,9........ a.Length; ...

  2. 【2017-02-26】String类、Math类、DateTime类

    一.String类 黑色小扳手 - 属性     后面不带括号紫色立方体 - 方法     后面带括号 字符串.Length  -  字符串长度,返回int类型 字符串.TrimStart() - 去 ...

  3. 【2017-2-26】C#String类、Math类、DateTime类

    String类 黑色小扳手:属性      后面不带括号 紫色小箱子:方法      后面带小括号 1.字符串.Length;   字符串长度,返回int类型 字符串的长度 2.字符串.TrimSta ...

  4. C#string类;math类;datetime类

    String类: .Length字符的长度   .Trim()去掉开头以及结尾的空格 .TrimStart()去掉字符串开头的空格 .TrimEnd()去掉字符串后面的空格   .ToUpper()全 ...

  5. string、math、random、datetime类

    1.string类 变量.Replace("想要替换掉的字符或字符串","转换后的字符或字符串");//替换 练习:判断邮箱格式是否正确            ...

  6. (C++)已知String类的定义,实现其函数体

    CString类的定义如下: class CMyString{ public: CMyString(const char* pData=NULL); CMyString(const CMyString ...

  7. java实验作业类的定义与描述

    1 //1三角形的定义与描述 2 package test; 3 4 public class sjx { 5 private double a,b,c; 6 7 public sjx(double ...

  8. string转DateTime(时间格式转换)

    1.不知道为什么时间在数据库用varchar(8)来保存,例如"19900505",但是这样的保存格式在处理时间的时候是非常不方便的. 但是转换不能用Convert.ToDateT ...

  9. JavaScript 类的定义和引用 JavaScript高级培训 自定义对象

    在Java语言中,我们可以定义自己的类,并根据这些类创建对象来使用,在Javascript中,我们也可以定义自己的类,例如定义User类.Hashtable类等等.     一,概述 在Java语言中 ...

随机推荐

  1. #最小生成树# #kruskal# ----- OpenJudge丛林中的路

    最小生成树 一个有 n 个结点的连通图的生成树是原图的极小连通子图,且包含原图中的所有 n 个结点,并且有保持图连通的最少的边.最小生成树可以用kruskal(克鲁斯卡尔)算法或prim(普里姆)算法 ...

  2. log4j.appender.stdout.layout.ConversionPattern

    http://501565246-qq-com.iteye.com/blog/1991881 http://wenku.baidu.com/link?url=e4Z9v9CY_gwRxHrggzHXx ...

  3. table固定前两列和最后一列,其他滑动显示

    网上搜的基本都是4个table做的,数据处理比较麻烦,写了个一个table的,此示例只固定了前两列和最后一列,和网上的不太一样. 网上搜的基本都是4个table做的,数据处理比较麻烦,写了个一个tab ...

  4. ubuntu服务器远程连接xshell,putty,xftp的简单使用教程

    当你自己千辛万苦终于搞到一个服务器(ubuntu(linux)系统的)之后,却不知道怎么进行时,xshell,putty,xftp是个很不错的选择 xshell和xftp是win下访问ubuntu(l ...

  5. pwnable.kr-fd-Writeup

    html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...

  6. vue2重写饿了么

    构建 vue有自己的脚手架构建工具vue-cli,使用起来非常方便,使用webpack来集成各种开发便捷工具,比如: 代码热更新,修改代码之后网页无刷新改变,对前端开发来说非常的方便 PostCss, ...

  7. UICollectionView 很简单的写个瀑布流

    你项目中要用到它吗? 可能会在你的项目中用到这玩意,最近也是要用就简单的写了一个 Demo.没多少代码,就不放Git了,下面会详细点的说说代码的,要还有什么问题的小伙伴可以直接Q我,也可以把Demo发 ...

  8. 数字信号处理MATLAB简单序列

    数字信号处理应用的几个基本序列: 1 单位样本序列 function mainImseq() clc clear disp('生成抽样序列'); y=imseq(,,); %调用样本函数,此时序列下标 ...

  9. [UWP]附加属性1:概述

    1. 什么是附加属性(attached property ) 附加属性依赖属性的一种特殊形式,常见的Grid.Row,Canvas.Left都是附加属性. /// <summary> // ...

  10. $.each()遍历json数据

    var json = [ {"id":"1","tagName":"apple"}, {"id":& ...