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; }
最新文章
- Struts2的模板和主题theme及自定义theme的使用
- Java基础(56):Java---Assertion的试用(华为OJ里的Java题目的用例检测就是用的断言)
- java 获取本机ip地址
- SSRS集成至Web
- linux环境下java读取sh脚本并执行
- 11个超棒的iOS开发学习网站
- <;Android基础>; (五) 广播机制
- NOIp2018爆零记
- [CC-CMPVIRS]Computer Virus
- 【iCore4 双核心板_uC/OS-II】例程六:信号量——任务同步
- Javascript定义变量
- Oracle11g ADG环境实施文档-1204
- EF Core中如何取消跟踪DbContext中所有被跟踪的实体
- k8s之使用secret获取私有仓库镜像
- Docker(五)-Dcoker容器
- 多目标线性规划求解方法及matlab实现
- Linux(RedHat) 开机时修改root密码
- Too Rich(贪心+DFS)
- 4013: [HNOI2015]实验比较
- CentOS基础命令大全