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 ...
随机推荐
- 微软 eshop 数据存储之sqlserver
微软的eshop项目写的很牛,学起来也比较吃力,最近公司刚好有一本书,说的就是.NET微服务,记下来. 因为微软对性能的要求,docker里面要有内存要求 安装dokcer,拉镜象 : docker ...
- Qt学习(一)
1. 简介 跨平台 GUI 通常有三种实现策略 API 映射 相当于将不同平台的 API 提取公共部分.界面库使用同一套 API,将其映射到不同的底层平台上面.相当于取交集 如wxWidgets. 优 ...
- [Perl]Windows 系统 Unicode 文件名操作(新建、重命名、枚举、复制)全攻略
[Perl] Windows 系统 Unicode 文件名操作(新建.重命名.枚举.复制)全攻略 环境 XP/WIN7 Perl v5.16 编辑整理:PerlMonk.523066680 常见的那些 ...
- HAOI2010 订货
题目链接:戳我 费用流. 将每天分成早上和晚上两个点.源点向早上连容量INF,费用为进货量的边.早上向汇点连容量供货量,费用0.早上向晚上连容量为S,费用为0的边.晚上向第二天早上连容量S,费用0.之 ...
- 性能测试工具Locust的使用----TaskSet类~~task任务嵌套
内容来自网络 http://blog.sina.com.cn/s/blog_a7ace3d80102w9r0.html TaskSet类 正如字面意思,TaskSet类定义了每个用户的任务集合,测试任 ...
- 关键字的使用 pass break continue
# ### 关键字的使用 # (1)pass 过 作用 作站位用的 if 5==5: pass i = 0 while i <5: pass #约定俗成,在循环里面什么也不行的情况下,给友好提示 ...
- HDU6333-2018ACM暑假多校联合训练1002-Harvest of Apples-莫队+费马小定理
题意很简单啦,求S(n,m)的值 通过打表我们可以知道 S(n + 1, m) = S(n, m) * 2 - C(n, m); S(n - 1, m) = (S(n, m) + C(n - 1, m ...
- 编译的 Ruby 2.3.0 缺少 openssl 支持的解决方法 (已解决)
我的系统是centos 7.5,已离线安装ruby-2.3.0,openssl-1.0.2l,rubygems-2.7.4 如下图: 但是在 gem sources -a http://gems.r ...
- classnofoundexception:org.springframework.ui.freemarker.FreeMarkerConfigurationFactory
这个是在整合freemarker的时候出现的问题,在添加依赖spring-context-support.jar之后就好了 但是我在搭建框架的时候出现的问题是明明添加了这个依赖,但是出现一个问题 出现 ...
- POJ3074 Sudoku
POJ3074 Sudoku 与POJ2676相比,这一题搜索时每一步都找到最好确定的点进行枚举 对于每行.每列.每个九宫格,都分别用一个9位二进制数保存还有那些数还可以填 对于每个位置,将其所在行. ...