Compare   比较字符串的内容,考虑文化背景(场所),确定某些字符是否相等

CompareOrdinal  与Compare一样,但不考虑文化背景

Format   格式化包含各种值的字符串和如何格式化每个值的说明符

IndexOf   定位字符串中第一次出现某个给定子字符串或字符的位置

IndexOfAny  定位字符串中第一次出现某个字符或一组字符的位置

LastIndexOf  与IndexOf一样,但定位最后一次出现的位置

LastIndexOfAny  与IndexOfAny,但定位最后一次出现的位置

PadLeft   在字符串的开头,通过添加指定的重复字符填充字符串

PadRight  在字符串的结尾,通过添加指定的重复字符填充字符串

Replace   用另一个字符或子字符串替换字符串中给定的字符或子字符串

常用C#字符串函数大全_string1、DateTime 数字型
常用C#字符串函数大全_stringSystem.DateTime currentTime
=new System.DateTime();
常用C#字符串函数大全_string
1.1 取当前年月日时分秒
常用C#字符串函数大全_stringcurrentTime
=System.DateTime.Now;
常用C#字符串函数大全_string
1.2 取当前年
常用C#字符串函数大全_string
int=currentTime.Year;
常用C#字符串函数大全_string
1.3 取当前月
常用C#字符串函数大全_string
int=currentTime.Month;
常用C#字符串函数大全_string
1.4 取当前日
常用C#字符串函数大全_string
int=currentTime.Day;
常用C#字符串函数大全_string
1.5 取当前时
常用C#字符串函数大全_string
int=currentTime.Hour;
常用C#字符串函数大全_string
1.6 取当前分
常用C#字符串函数大全_string
int=currentTime.Minute;
常用C#字符串函数大全_string
1.7 取当前秒
常用C#字符串函数大全_string
int=currentTime.Second;
常用C#字符串函数大全_string
1.8 取当前毫秒
常用C#字符串函数大全_string
int 毫秒=currentTime.Millisecond;
常用C#字符串函数大全_string(变量可用中文)
常用C#字符串函数大全_string
2、Int32.Parse(变量) Int32.Parse("常量")
常用C#字符串函数大全_string字符型转换 转为32位数字型
常用C#字符串函数大全_string
常用C#字符串函数大全_string
3、 变量.ToString()
常用C#字符串函数大全_string字符型转换 转为字符串
常用C#字符串函数大全_string
12345.ToString("n"); //生成 12,345.00
常用C#字符串函数大全_string
12345.ToString("C"); //生成 ¥12,345.00
常用C#字符串函数大全_string
12345.ToString("e"); //生成 1.234500e+004
常用C#字符串函数大全_string
12345.ToString("f4"); //生成 12345.0000
常用C#字符串函数大全_string
12345.ToString("x"); //生成 3039 (16进制)
常用C#字符串函数大全_string
12345.ToString("p"); //生成 1,234,500.00%
常用C#字符串函数大全_string

常用C#字符串函数大全_string
常用C#字符串函数大全_string
4、变量.Length 数字型
常用C#字符串函数大全_string取字串长度:
常用C#字符串函数大全_string如:
string str="中国";
常用C#字符串函数大全_string
int Len = str.Length ; //Len是自定义变量, str是求测的字串的变量名
常用C#字符串函数大全_string

常用C#字符串函数大全_string
5、System.Text.Encoding.Default.GetBytes(变量)
常用C#字符串函数大全_string字码转换 转为比特码
常用C#字符串函数大全_string如:
byte[] bytStr = System.Text.Encoding.Default.GetBytes(str);
常用C#字符串函数大全_string然后可得到比特长度:
常用C#字符串函数大全_stringlen
= bytStr.Length;
常用C#字符串函数大全_string
常用C#字符串函数大全_string
6、System.Text.StringBuilder("")
常用C#字符串函数大全_string字符串相加,(
+号是不是也一样?)
常用C#字符串函数大全_string如:System.Text.StringBuilder sb
= new System.Text.StringBuilder("");
常用C#字符串函数大全_stringsb.Append(
"中华");
常用C#字符串函数大全_stringsb.Append(
"人民");
常用C#字符串函数大全_stringsb.Append(
"共和国");
常用C#字符串函数大全_string
常用C#字符串函数大全_string
7、变量.Substring(参数1,参数2);
常用C#字符串函数大全_string截取字串的一部分,参数1为左起始位数,参数2为截取几位。
常用C#字符串函数大全_string如:
string s1 = str.Substring(0,2);
常用C#字符串函数大全_string
常用C#字符串函数大全_string
8、String user_IP=Request.ServerVariables["REMOTE_ADDR"].ToString();
常用C#字符串函数大全_string取远程用户IP地址
常用C#字符串函数大全_string
常用C#字符串函数大全_string
9、穿过代理服务器取远程用户真实IP地址:
常用C#字符串函数大全_xml_59
if(Request.ServerVariables["HTTP_VIA"]!=null){
常用C#字符串函数大全_string_60
string user_IP=Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
常用C#字符串函数大全_equals_61}
else{
常用C#字符串函数大全_string_60
string user_IP=Request.ServerVariables["REMOTE_ADDR"].ToString();
常用C#字符串函数大全_c#_63}

常用C#字符串函数大全_string
常用C#字符串函数大全_string
10、 Session["变量"];
常用C#字符串函数大全_string存取Session值;
常用C#字符串函数大全_string如,赋值: Session[
"username"]="小布什";
常用C#字符串函数大全_string
常用C#字符串函数大全_string取值: Object objName
=Session["username"];
常用C#字符串函数大全_stringString strName
=objName.ToString();
常用C#字符串函数大全_string清空: Session.RemoveAll();
常用C#字符串函数大全_string
常用C#字符串函数大全_string
11、String str=Request.QueryString["变量"];
常用C#字符串函数大全_string用超链接传送变量。
常用C#字符串函数大全_string如在任一页中建超链接:
<a href=Edit.aspx?fbid=23>点击</a>
常用C#字符串函数大全_string在Edit.aspx页中取值:String str
=Request.QueryString["fdid"];
常用C#字符串函数大全_string
常用C#字符串函数大全_string
12、DOC对象.CreateElement("新建节点名");
常用C#字符串函数大全_string创建XML文档新节点
常用C#字符串函数大全_string
常用C#字符串函数大全_string
13、父节点.AppendChild(子节点);
常用C#字符串函数大全_string将新建的子节点加到XML文档父节点下
常用C#字符串函数大全_string
常用C#字符串函数大全_string
14、 父节点.RemoveChild(节点);
常用C#字符串函数大全_string删除节点
常用C#字符串函数大全_string
常用C#字符串函数大全_string
15、Response
常用C#字符串函数大全_stringResponse.Write(
"字串");
常用C#字符串函数大全_stringResponse.Write(变量);
常用C#字符串函数大全_string向页面输出。
常用C#字符串函数大全_string
常用C#字符串函数大全_stringResponse.Redirect(
"URL地址");
常用C#字符串函数大全_string跳转到URL指定的页面
常用C#字符串函数大全_string
常用C#字符串函数大全_string
16char.IsWhiteSpce(字串变量,位数)——逻辑型
常用C#字符串函数大全_string查指定位置是否空字符;
常用C#字符串函数大全_string如:
常用C#字符串函数大全_string
string str="中国 人民";
常用C#字符串函数大全_stringResponse.Write(
char.IsWhiteSpace(str,2)); //结果为:True, 第一个字符是0位,2是第三个字符。
常用C#字符串函数大全_string

常用C#字符串函数大全_string
17char.IsPunctuation('字符') --逻辑型
常用C#字符串函数大全_string查字符是否是标点符号
常用C#字符串函数大全_string如:Response.Write(
char.IsPunctuation('A')); //返回:False
常用C#字符串函数大全_string

常用C#字符串函数大全_string
18、(int)'字符'
常用C#字符串函数大全_string把字符转为数字,查代码点,注意是单引号。
常用C#字符串函数大全_string如:
常用C#字符串函数大全_stringResponse.Write((
int)''); //结果为中字的代码:20013
常用C#字符串函数大全_string

常用C#字符串函数大全_string
19、(char)代码
常用C#字符串函数大全_string把数字转为字符,查代码代表的字符。
常用C#字符串函数大全_string如:
常用C#字符串函数大全_stringResponse.Write((
char)22269); //返回“国”字。
常用C#字符串函数大全_string

常用C#字符串函数大全_string
20、 Trim()
常用C#字符串函数大全_string清除字串前后空格
常用C#字符串函数大全_string
常用C#字符串函数大全_string
21 、字串变量.Replace("子字串","替换为")
常用C#字符串函数大全_string字串替换
常用C#字符串函数大全_string如:
常用C#字符串函数大全_string
string str="中国";
常用C#字符串函数大全_stringstr
=str.Replace("",""); //将国字换为央字
常用C#字符串函数大全_string
Response.Write(str); //输出结果为“中央”
常用C#字符串函数大全_string

常用C#字符串函数大全_string再如:(这个非常实用)
常用C#字符串函数大全_string
常用C#字符串函数大全_string
string str="这是<script>脚本";
常用C#字符串函数大全_stringstr
=str.Replace("<","<font><</font>"); //将左尖括号替换为<font> 与 < 与 </font> (或换为<,但估计经XML存诸后,再提出仍会还原)
常用C#字符串函数大全_string
Response.Write(str); //显示为:“这是<script>脚本”
常用C#字符串函数大全_string

常用C#字符串函数大全_string如果不替换,
<script>将不显示,如果是一段脚本,将运行;而替换后,脚本将不运行。
常用C#字符串函数大全_string这段代码的价值在于:你可以让一个文本中的所有HTML标签失效,全部显示出来,保护你的具有交互性的站点。
常用C#字符串函数大全_string具体实现:将你的表单提交按钮脚本加上下面代码:
常用C#字符串函数大全_string
string strSubmit=label1.Text; //label1是你让用户提交数据的控件ID。
常用C#字符串函数大全_string
strSubmit=strSubmit.Replace("<","<font><</font>");
常用C#字符串函数大全_string然后保存或输出strSubmit。
常用C#字符串函数大全_string用此方法还可以简单实现UBB代码。
常用C#字符串函数大全_string
常用C#字符串函数大全_string
22、Math.Max(i,j)
常用C#字符串函数大全_string取i与j中的最大值
常用C#字符串函数大全_string
int x=Math.Max(5,10); // x将取值 10
常用C#字符串函数大全_string

常用C#字符串函数大全_string加一点吧
23、字串对比常用C#字符串函数大全_c#_144常用C#字符串函数大全_c#_144
常用C#字符串函数大全_string加一点吧
常用C#字符串函数大全_string
常用C#字符串函数大全_c#_148
23、字串对比一般都用: if(str1==str2){ } , 但还有别的方法:
常用C#字符串函数大全_string
常用C#字符串函数大全_string(
1)、
常用C#字符串函数大全_string
string str1; str2
常用C#字符串函数大全_string
//语法: str1.EndsWith(str2); __检测字串str1是否以字串str2结尾,返回布尔值.如:
常用C#字符串函数大全_equals_153
if(str1.EndsWith(str2)){ Response.Write("字串str1是以"+str2+"结束的"); }
常用C#字符串函数大全_string
常用C#字符串函数大全_string(
2)、
常用C#字符串函数大全_string
//语法:str1.Equals(str2); __检测字串str1是否与字串str2相等,返回布尔值,用法同上.
常用C#字符串函数大全_string

常用C#字符串函数大全_string(
3)、
常用C#字符串函数大全_string
//语法 Equals(str1,str2); __检测字串str1是否与字串str2相等,返回布尔值,用法同上.
常用C#字符串函数大全_string

常用C#字符串函数大全_string
24、IndexOf() 、LastIndexOf()
常用C#字符串函数大全_string查找字串中指定字符或字串首次(最后一次)出现的位置,返回索引值,如:
常用C#字符串函数大全_stringstr1.IndexOf(
""); //查找“字”在str1中的索引值(位置)
常用C#字符串函数大全_string
str1.IndexOf("字串");//查找“字串”的第一个字符在str1中的索引值(位置)
常用C#字符串函数大全_string
str1.IndexOf("字串",3,2);//从str1第4个字符起,查找2个字符,查找“字串”的第一个字符在str1中的索引值(位置)
常用C#字符串函数大全_string

常用C#字符串函数大全_string
25、Insert()
常用C#字符串函数大全_string在字串中指定索引位插入指定字符。如:
常用C#字符串函数大全_stringstr1.Insert(
1,"");在str1的第二个字符处插入“字”,如果str1="中国",插入后为“中字国”;
常用C#字符串函数大全_string
常用C#字符串函数大全_string
26、PadLeft()、PadRight()
常用C#字符串函数大全_string在字串左(或右)加空格或指定char字符,使字串达到指定长度,如:
常用C#字符串函数大全_string
<%
常用C#字符串函数大全_string
string str1="中国人";
常用C#字符串函数大全_stringstr1
=str1.PadLeft(10,'1'); //无第二参数为加空格
常用C#字符串函数大全_string
Response.Write(str1); //结果为“1111111中国人” , 字串长为10
常用C#字符串函数大全_string
%>
常用C#字符串函数大全_string
常用C#字符串函数大全_string
27、Remove()
常用C#字符串函数大全_string从指定位置开始删除指定数的字符
常用C#字符串函数大全_xml_181字串对比一般都用:
if(str1==str2){ } , 但还有别的方法:
常用C#字符串函数大全_string
常用C#字符串函数大全_string
1
常用C#字符串函数大全_string
string str1; str2
常用C#字符串函数大全_string
//语法: str1.EndsWith(str2); __检测字串str1是否以字串str2结尾,返回布尔值.如:
常用C#字符串函数大全_session_186
if(str1.EndsWith(str2)){ Response.Write("字串str1是以"+str2+"结束的"); }
常用C#字符串函数大全_string
常用C#字符串函数大全_string
2
常用C#字符串函数大全_string
//语法:str1.Equals(str2); __检测字串str1是否与字串str2相等,返回布尔值,用法同上.
常用C#字符串函数大全_string

常用C#字符串函数大全_string
3
常用C#字符串函数大全_string
//语法 Equals(str1,str2); __检测字串str1是否与字串str2相等,返回布尔值,用法同上.
常用C#字符串函数大全_string

常用C#字符串函数大全_stringIndexOf()
常用C#字符串函数大全_string查找字串中指定字符或字串首次出现的位置,返首索引值,如:
常用C#字符串函数大全_stringstr1.IndexOf(
""); //查找“字”在str1中的索引值(位置)
常用C#字符串函数大全_string
str1.IndexOf("字串");//查找“字串”的第一个字符在str1中的索引值(位置)
常用C#字符串函数大全_string
str1.IndexOf("字串",3,2);//从str1第4个字符起,查找2个字符,查找“字串”的第一个字符在str1中的索引值(位置)
常用C#字符串函数大全_string

常用C#字符串函数大全_string
1.9 取中文日期显示——年月日时分
常用C#字符串函数大全_string
string strY=currentTime.ToString("f"); //不显示秒
常用C#字符串函数大全_string

常用C#字符串函数大全_string
1.10 取中文日期显示_年月
常用C#字符串函数大全_string
string strYM=currentTime.ToString("y");
常用C#字符串函数大全_string
常用C#字符串函数大全_string
1.11 取中文日期显示_月日
常用C#字符串函数大全_string
string strMD=currentTime.ToString("m");
常用C#字符串函数大全_string
常用C#字符串函数大全_string
1.12 取当前年月日,格式为:2003-9-23
常用C#字符串函数大全_string
string strYMD=currentTime.ToString("d");
常用C#字符串函数大全_string
常用C#字符串函数大全_string
1.13 取当前时分,格式为:1424
常用C#字符串函数大全_string
string strT=currentTime.ToString("t");
常用C#字符串函数大全_string更新一下, 上面不能编辑:
常用C#字符串函数大全_string
常用C#字符串函数大全_stringc#.net函数和方法集(大家一起来加啊)
常用C#字符串函数大全_string
常用C#字符串函数大全_string
常用C#字符串函数大全_string
1、DateTime 数字型
常用C#字符串函数大全_stringSystem.DateTime currentTime
=new System.DateTime();
常用C#字符串函数大全_string
1.1 取当前年月日时分秒
常用C#字符串函数大全_stringcurrentTime
=System.DateTime.Now;
常用C#字符串函数大全_string
1.2 取当前年
常用C#字符串函数大全_string
int=currentTime.Year;
常用C#字符串函数大全_string
1.3 取当前月
常用C#字符串函数大全_string
int=currentTime.Month;
常用C#字符串函数大全_string
1.4 取当前日
常用C#字符串函数大全_string
int=currentTime.Day;
常用C#字符串函数大全_string
1.5 取当前时
常用C#字符串函数大全_string
int=currentTime.Hour;
常用C#字符串函数大全_string
1.6 取当前分
常用C#字符串函数大全_string
int=currentTime.Minute;
常用C#字符串函数大全_string
1.7 取当前秒
常用C#字符串函数大全_string
int=currentTime.Second;
常用C#字符串函数大全_string
1.8 取当前毫秒
常用C#字符串函数大全_string
int 毫秒=currentTime.Millisecond;
常用C#字符串函数大全_string(变量可用中文)
常用C#字符串函数大全_string
常用C#字符串函数大全_string
1.9 取中文日期显示——年月日时分
常用C#字符串函数大全_string
string strY=currentTime.ToString("f"); //不显示秒
常用C#字符串函数大全_string

常用C#字符串函数大全_string
1.10 取中文日期显示_年月
常用C#字符串函数大全_string
string strYM=currentTime.ToString("y");
常用C#字符串函数大全_string
常用C#字符串函数大全_string
1.11 取中文日期显示_月日
常用C#字符串函数大全_string
string strMD=currentTime.ToString("m");
常用C#字符串函数大全_string
常用C#字符串函数大全_string
1.12 取中文年月日
常用C#字符串函数大全_string
string strYMD=currentTime.ToString("D");
常用C#字符串函数大全_string
常用C#字符串函数大全_string
1.13 取当前时分,格式为:1424
常用C#字符串函数大全_string
string strT=currentTime.ToString("t");
常用C#字符串函数大全_string
常用C#字符串函数大全_string
1.14 取当前时间,格式为:2003-09-23T14:46:48
常用C#字符串函数大全_string
string strT=currentTime.ToString("s");
常用C#字符串函数大全_string
常用C#字符串函数大全_string
1.15 取当前时间,格式为:2003-09-23 14:48:30Z
常用C#字符串函数大全_string
string strT=currentTime.ToString("u");
常用C#字符串函数大全_string
常用C#字符串函数大全_string
1.16 取当前时间,格式为:2003-09-23 14:48
常用C#字符串函数大全_string
string strT=currentTime.ToString("g");
常用C#字符串函数大全_string
常用C#字符串函数大全_string
1.17 取当前时间,格式为:Tue, 23 Sep 2003 14:52:40 GMT
常用C#字符串函数大全_string
string strT=currentTime.ToString("r");
常用C#字符串函数大全_string
常用C#字符串函数大全_string
1.18获得当前时间 n 天后的日期时间
常用C#字符串函数大全_stringDateTime newDay
= DateTime.Now.AddDays(100);
常用C#字符串函数大全_string
常用C#字符串函数大全_string
2、Int32.Parse(变量) Int32.Parse("常量")
常用C#字符串函数大全_string字符型转换 转为32位数字型
常用C#字符串函数大全_string
常用C#字符串函数大全_string
3、 变量.ToString()
常用C#字符串函数大全_string字符型转换 转为字符串
常用C#字符串函数大全_string
12345.ToString("n"); //生成 12,345.00
常用C#字符串函数大全_string
12345.ToString("C"); //生成 ¥12,345.00
常用C#字符串函数大全_string
12345.ToString("e"); //生成 1.234500e+004
常用C#字符串函数大全_string
12345.ToString("f4"); //生成 12345.0000
常用C#字符串函数大全_string
12345.ToString("x"); //生成 3039 (16进制)
常用C#字符串函数大全_string
12345.ToString("p"); //生成 1,234,500.00%
常用C#字符串函数大全_string

常用C#字符串函数大全_string
常用C#字符串函数大全_string
4、变量.Length 数字型
常用C#字符串函数大全_string取字串长度:
常用C#字符串函数大全_string如:
string str="中国";
常用C#字符串函数大全_string
int Len = str.Length ; //Len是自定义变量, str是求测的字串的变量名
常用C#字符串函数大全_string

常用C#字符串函数大全_string
5、System.Text.Encoding.Default.GetBytes(变量)
常用C#字符串函数大全_string字码转换 转为比特码
常用C#字符串函数大全_string如:
byte[] bytStr = System.Text.Encoding.Default.GetBytes(str);
常用C#字符串函数大全_string然后可得到比特长度:
常用C#字符串函数大全_stringlen
= bytStr.Length;
常用C#字符串函数大全_string
常用C#字符串函数大全_string
6、System.Text.StringBuilder("")
常用C#字符串函数大全_string字符串相加,(
+号是不是也一样?)
常用C#字符串函数大全_string如:System.Text.StringBuilder sb
= new System.Text.StringBuilder("");
常用C#字符串函数大全_stringsb.Append(
"中华");
常用C#字符串函数大全_stringsb.Append(
"人民");
常用C#字符串函数大全_stringsb.Append(
"共和国");
常用C#字符串函数大全_string
常用C#字符串函数大全_string
7、变量.Substring(参数1,参数2);
常用C#字符串函数大全_string截取字串的一部分,参数1为左起始位数,参数2为截取几位。
常用C#字符串函数大全_string如:
string s1 = str.Substring(0,2);
常用C#字符串函数大全_string
常用C#字符串函数大全_string
8、String user_IP=Request.ServerVariables["REMOTE_ADDR"].ToString();
常用C#字符串函数大全_string取远程用户IP地址
常用C#字符串函数大全_string
常用C#字符串函数大全_string
9、穿过代理服务器取远程用户真实IP地址:
常用C#字符串函数大全_c#_308
if(Request.ServerVariables["HTTP_VIA"]!=null){
常用C#字符串函数大全_string_60
string user_IP=Request.ServerVariables["HTTP_X_FORWARDED_FOR"].ToString();
常用C#字符串函数大全_string_310}
else{
常用C#字符串函数大全_string_60
string user_IP=Request.ServerVariables["REMOTE_ADDR"].ToString();
常用C#字符串函数大全_c#_63}

常用C#字符串函数大全_string
常用C#字符串函数大全_string
10、 Session["变量"];
常用C#字符串函数大全_string存取Session值;
常用C#字符串函数大全_string如,赋值: Session[
"username"]="小布什";
常用C#字符串函数大全_string
常用C#字符串函数大全_string取值: Object objName
=Session["username"];
常用C#字符串函数大全_stringString strName
=objName.ToString();
常用C#字符串函数大全_string清空: Session.RemoveAll();
常用C#字符串函数大全_string
常用C#字符串函数大全_string
11、String str=Request.QueryString["变量"];
常用C#字符串函数大全_string用超链接传送变量。
常用C#字符串函数大全_string如在任一页中建超链接:
<a href=Edit.aspx?fbid=23>点击</a>
常用C#字符串函数大全_string在Edit.aspx页中取值:String str
=Request.QueryString["fdid"];
常用C#字符串函数大全_string
常用C#字符串函数大全_string
12、DOC对象.CreateElement("新建节点名");
常用C#字符串函数大全_string创建XML文档新节点
常用C#字符串函数大全_string
常用C#字符串函数大全_string
13、父节点.AppendChild(子节点);
常用C#字符串函数大全_string将新建的子节点加到XML文档父节点下
常用C#字符串函数大全_string
常用C#字符串函数大全_string
14、 父节点.RemoveChild(节点);
常用C#字符串函数大全_string删除节点
常用C#字符串函数大全_string
常用C#字符串函数大全_string
15、Response
常用C#字符串函数大全_stringResponse.Write(
"字串");
常用C#字符串函数大全_stringResponse.Write(变量);
常用C#字符串函数大全_string向页面输出。
常用C#字符串函数大全_string
常用C#字符串函数大全_stringResponse.Redirect(
"URL地址");
常用C#字符串函数大全_string跳转到URL指定的页面
常用C#字符串函数大全_string
常用C#字符串函数大全_string
16char.IsWhiteSpce(字串变量,位数)——逻辑型
常用C#字符串函数大全_string查指定位置是否空字符;
常用C#字符串函数大全_string如:
常用C#字符串函数大全_string
string str="中国 人民";
常用C#字符串函数大全_stringResponse.Write(
char.IsWhiteSpace(str,2)); //结果为:True, 第一个字符是0位,2是第三个字符。
常用C#字符串函数大全_string

常用C#字符串函数大全_string
17char.IsPunctuation('字符') --逻辑型
常用C#字符串函数大全_string查字符是否是标点符号
常用C#字符串函数大全_string如:Response.Write(
char.IsPunctuation('A')); //返回:False
常用C#字符串函数大全_string

常用C#字符串函数大全_string
18、(int)'字符'
常用C#字符串函数大全_string把字符转为数字,查代码点,注意是单引号。
常用C#字符串函数大全_string如:
常用C#字符串函数大全_stringResponse.Write((
int)''); //结果为中字的代码:20013
常用C#字符串函数大全_string

常用C#字符串函数大全_string
19、(char)代码
常用C#字符串函数大全_string把数字转为字符,查代码代表的字符。
常用C#字符串函数大全_string如:
常用C#字符串函数大全_stringResponse.Write((
char)22269); //返回“国”字。
常用C#字符串函数大全_string

常用C#字符串函数大全_string
20、 Trim()
常用C#字符串函数大全_string清除字串前后空格
常用C#字符串函数大全_string
常用C#字符串函数大全_string
21 、字串变量.Replace("子字串","替换为")
常用C#字符串函数大全_string字串替换
常用C#字符串函数大全_string如:
常用C#字符串函数大全_string
string str="中国";
常用C#字符串函数大全_stringstr
=str.Replace("",""); //将国字换为央字
常用C#字符串函数大全_string
Response.Write(str); //输出结果为“中央”
常用C#字符串函数大全_string

常用C#字符串函数大全_string再如:(这个非常实用)
常用C#字符串函数大全_string
常用C#字符串函数大全_string
string str="这是<script>脚本";
常用C#字符串函数大全_stringstr
=str.Replace("<","<font><</font>"); //将左尖括号替换为<font> 与 < 与 </font> (或换为<,但估计经XML存诸后,再提出仍会还原)
常用C#字符串函数大全_string
Response.Write(str); //显示为:“这是<script>脚本”
常用C#字符串函数大全_string

常用C#字符串函数大全_string如果不替换,
<script>将不显示,如果是一段脚本,将运行;而替换后,脚本将不运行。
常用C#字符串函数大全_string这段代码的价值在于:你可以让一个文本中的所有HTML标签失效,全部显示出来,保护你的具有交互性的站点。
常用C#字符串函数大全_string具体实现:将你的表单提交按钮脚本加上下面代码:
常用C#字符串函数大全_string
string strSubmit=label1.Text; //label1是你让用户提交数据的控件ID。
常用C#字符串函数大全_string
strSubmit=strSubmit.Replace("<","<font><</font>");
常用C#字符串函数大全_string然后保存或输出strSubmit。
常用C#字符串函数大全_string用此方法还可以简单实现UBB代码。
常用C#字符串函数大全_string
常用C#字符串函数大全_string
22、Math.Max(i,j)
常用C#字符串函数大全_string取i与j中的最大值
常用C#字符串函数大全_string
int x=Math.Max(5,10); // x将取值 10
常用C#字符串函数大全_string

常用C#字符串函数大全_equals_392
23、字串对比一般都用: if(str1==str2){ } , 但还有别的方法:
常用C#字符串函数大全_string
常用C#字符串函数大全_string(
1)、
常用C#字符串函数大全_string
string str1; str2
常用C#字符串函数大全_string
//语法: str1.EndsWith(str2); __检测字串str1是否以字串str2结尾,返回布尔值.如:
常用C#字符串函数大全_脚本_397
if(str1.EndsWith(str2)){ Response.Write("字串str1是以"+str2+"结束的"); }
常用C#字符串函数大全_string
常用C#字符串函数大全_string(
2)、
常用C#字符串函数大全_string
//语法:str1.Equals(str2); __检测字串str1是否与字串str2相等,返回布尔值,用法同上.
常用C#字符串函数大全_string

常用C#字符串函数大全_string(
3)、
常用C#字符串函数大全_string
//语法 Equals(str1,str2); __检测字串str1是否与字串str2相等,返回布尔值,用法同上.
常用C#字符串函数大全_string

常用C#字符串函数大全_string
24、IndexOf() 、LastIndexOf()
常用C#字符串函数大全_string查找字串中指定字符或字串首次(最后一次)出现的位置,返回索引值,如:
常用C#字符串函数大全_stringstr1.IndexOf(
""); //查找“字”在str1中的索引值(位置)
常用C#字符串函数大全_string
str1.IndexOf("字串");//查找“字串”的第一个字符在str1中的索引值(位置)
常用C#字符串函数大全_string
str1.IndexOf("字串",3,2);//从str1第4个字符起,查找2个字符,查找“字串”的第一个字符在str1中的索引值(位置)
常用C#字符串函数大全_string

常用C#字符串函数大全_string
25、Insert()
常用C#字符串函数大全_string在字串中指定索引位插入指定字符。如:
常用C#字符串函数大全_stringstr1.Insert(
1,"");在str1的第二个字符处插入“字”,如果str1="中国",插入后为“中字国”;
常用C#字符串函数大全_string
常用C#字符串函数大全_string
26、PadLeft()、PadRight()
常用C#字符串函数大全_string在字串左(或右)加空格或指定char字符,使字串达到指定长度,如:
常用C#字符串函数大全_string
<%
常用C#字符串函数大全_string
string str1="中国人";
常用C#字符串函数大全_stringstr1
=str1.PadLeft(10,'1'); //无第二参数为加空格
常用C#字符串函数大全_string
Response.Write(str1); //结果为“1111111中国人” , 字串长为10
常用C#字符串函数大全_string
%>
常用C#字符串函数大全_string
常用C#字符串函数大全_string
27、Remove()
常用C#字符串函数大全_string从指定位置开始删除指定数的字符
常用C#字符串函数大全_string
<%
常用C#字符串函数大全_string
string str1="我是萨达姆的崇拜者之一";
常用C#字符串函数大全_stringResponse.Write(str1.Remove(
5,4)); //结果为“我是萨达姆之一”
常用C#字符串函数大全_string
%>