String.Compare 方法 (String, Int32, String, Int32, Int32)
String.Compare 方法 (String, Int32, String, Int32, Int32)
对两个指定的 String 对象的子字符串进行比较,并返回一个指示二者在排序顺序中的相对位置的整数。
参数
- strA
- 类型:System.String
要在比较中使用的第一个字符串。
- indexA
- 类型:System.Int32
strA 中子字符串的位置。
- strB
- 类型:System.String
要在比较中使用的第二个字符串。
- indexB
- 类型:System.Int32
strB 中子字符串的位置。
- length
- 类型:System.Int32
要比较的子字符串中字符的最大数量。
返回值
类型:System.Int32
一个 32 位有符号整数,指示两个比较数之间的词法关系。
值 Condition
小于零 strA 中的子字符串小于 strB 中的子字符串。
零 子字符串相等,或者 length 为零。
大于零 strA 中的子字符串大于 strB 中的子字符串。
// Sample for String.Compare(String, Int32, String, Int32, Int32)
using System; class Sample {
public static void Main() {
// 0123456
String str1 = "machine";
String str2 = "device";
String str;
int result; Console.WriteLine();
Console.WriteLine("str1 = '{0}', str2 = '{1}'", str1, str2);
result = String.Compare(str1, 2, str2, 0, 2);
str = ((result < 0) ? "less than" : ((result > 0) ? "greater than" : "equal to"));
Console.Write("Substring '{0}' in '{1}' is ", str1.Substring(2, 2), str1);
Console.Write("{0} ", str);
Console.WriteLine("substring '{0}' in '{1}'.", str2.Substring(0, 2), str2);
}
}
/*
This example produces the following results: str1 = 'machine', str2 = 'device'
Substring 'ch' in 'machine' is less than substring 'de' in 'device'.
*/
http://msdn.microsoft.com/zh-cn/library/x7tax739.aspx
.csharpcode, .csharpcode pre
{
font-size: small;
color: black;
font-family: consolas, "Courier New", courier, monospace;
background-color: #ffffff;
/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt
{
background-color: #f4f4f4;
width: 100%;
margin: 0em;
}
.csharpcode .lnum { color: #606060; }
String.Compare 方法 (String, Int32, String, Int32, Int32)的更多相关文章
- C# 字符串比较大小 string.Compare()方法
string.Compare方法,用来比较2个字符串值得大小 string.Compare(str1, str2, true); 返回值: 1 : str1大于str2 0 : str1等于str2 ...
- 深入解析字符串的比较方法:“==”操作符;String.Equals方法;String.Compare方法;String.CompareOrdinal方法。
1:要判断2个字符串变量是否相等,最高效的方法是看它们是否指向相同的内存地址.前面使用RefernceEquals方法来比较.如果2个变量指向的是不同的内存地址,那么就需要逐字符的比较2个字符串的变量 ...
- C#基础知识之字符串比较方法:“==”操作符;RefernceEquals;String.Equals方法;String.Compare方法;String.CompareOrdinal方法。
一.“==”操作符:String.Equals:ReferenceEquals 方法 1.在编程中实际上我们只需要这两种比较,c#中类型也就这两种 (1)值类型的比较:一般我们就是判断两个值类型实例各 ...
- string.Compare()方法
判断字符串中是否包含一个值 返回一个值,该值指示指定的 String 对象是否出现在此字符串中. String a = "abcd"; if(source.a("a&qu ...
- String.equals()方法、整理String类的Length()、charAt()、 getChars()、replace()、 toUpperCase()、 toLowerCase()、trim()、toCharArray()
equals 是比较的两个字符串是否一样 length() 返回字符串的长度 charAt (int index) 返回index所指定的字符 getChars(int srcBegin,int sr ...
- 1,字符是否为空,2,比较两个字符大小。String.Compare(String, String)。string.IsNullOrEmpty(string)
1, String.Compare 方法 (String, String) 比较两个指定的 String 对象. 值 条件 小于零 strA 小于 strB. 零 strA 等于 strB. 大于零 ...
- 警惕使用WebClient.DownloadFile(string uri,string filePath)方法
原文:警惕使用WebClient.DownloadFile(string uri,string filePath)方法 WebClient.DownloadFile(string uri,string ...
- java中Object转换成int或String类型方法
转载: http://www.cnblogs.com/1020182600HENG/p/6137206.html Object obj = getObject(); if(obj instanceof ...
- 【转载】 C#使用string.IsNullOrWhiteSpace方法判断字符串是否为非空字符
在C#编程过程中,很多时候需要判断传入过来的字符串是否为Null或者空字符或者空白字符,此时就可以使用到string.IsNullOrWhiteSpace方法来判断,如果字符串为null或者空字符Em ...
随机推荐
- 也说AOP
前言 1.引言 2.Aop概念 3.Aop实践 4.总结 一.引言 对于初入行的小白来讲,aop,ioc这两个程序设计思想总是傻傻分不清,不知道是个什么东东?别人再一谈各种框架更是云里雾里...博主今 ...
- Entity Framework 6 暂停重试执行策略
EF6引入一个弹性连接的功能,也就是允许重新尝试执行失败的数据库操作.某些复杂的场景中,可能需要启用或停用重试执行的策略,但是EF框架暂时尚未提供直接的设置开关,将来可能会加入这种配置.幸运的是,很容 ...
- Unit Vector Compression
Recently, I compared a few methods for compressing generic unit vectors. The method used in Cry Engi ...
- 903. Valid Permutations for DI Sequence
We are given S, a length n string of characters from the set {'D', 'I'}. (These letters stand for &q ...
- PTA 7-2 深入虎穴 (30 分)
著名的王牌间谍 007 需要执行一次任务,获取敌方的机密情报.已知情报藏在一个地下迷宫里,迷宫只有一个入口,里面有很多条通路,每条路通向一扇门.每一扇门背后或者是一个房间,或者又有很多条路,同样是每条 ...
- Servlet实现禁用cookie重写URL获取session
前言 一个女人让他的程序员丈夫去商店买东西:你去附近的商店买些鸡蛋,如果有香蕉的话,买8个回来,这个丈夫买了8个鸡蛋回来,他的妻子大吃一惊:你为什么买了8个鸡蛋?! 程序员丈夫回答:因为他们有香蕉. ...
- MySQL大数据高并发处理之-查询的优化
http://www.php1.cn/Content/MySQL_DaShuJuGaoBingFaChuLiZhi_-_ChaXunDeYouHua.html
- Tutorial 01 4,5题
.任务四: 程序设计思想:利用Math.random()产生一个char类型的字符,再利用for循环是他们相加,最后将他们放在一个消息框中输出. 程序流程图: 源程序: p ...
- Mongo限制规则
文章翻译自来源:http://docs.mongodb.org/manual/reference/limits/#limit-bson-document-size 一.BSON 文档 1.BSON文档 ...
- TX2 内核编译
准备工作 版本:jetpack3.1,R28.1,TX2 虚拟机:ubuntu14.04 参考文档.编译工具链.源码下载 编译 主要步骤记载如下: export CROSS_COMPILE=<c ...