C# 字符串方法

王林
发布: 2023-09-11 09:21:04
转载
1136人浏览过

c# 字符串方法

String 类有许多方法可以帮助您处理字符串对象。下表列出了一些最常用的方法 -

Sr.No 方法及说明
1 public static int Compare(string strA, string strB)

比较两个指定的字符串对象并返回一个整数,指示它们在排序顺序中的相对位置。

2 public static int Compare(string strA, string strB, boolignoreCase) strong>

比较两个指定的字符串对象并返回一个整数,指示它们在排序顺序中的相对位置。但是,如果布尔参数为 true,则忽略大小写。

3 public static string Concat(string str0, string str1)

连接两个字符串对象。

4 public static string Concat(string str0, string str1, string str2)

连接三个字符串对象。

5 公共静态字符串Concat(字符串str0,字符串str1,字符串str2,字符串str3)

连接四个字符串对象。

6 public bool Contains(string value)

返回一个值,指示指定的 String 对象是否出现在该字符串中。

7 public static string Copy(string str)

创建一个与指定值相同的新 String 对象字符串。

8 public void CopyTo(int sourceIndex, char[] 目的地, int destinationIndex, int count)

将指定数量的字符从 String 对象的指定位置复制到 Unicode 字符数组中的指定位置。

9 public bool EndsWith(string value)

判断是否字符串对象的末尾与指定字符串匹配。

10 public bool equals(string value)

判断当前String对象和指定String对象是否具有相同的值。

11 public static bool Equals(string a, string b)

判断两个指定的String对象是否相同

让我们看一个在 C# 中使用 Contains() 方法的示例。 Contains(string value) 返回一个值,指示指定的 String 对象是否出现在此字符串中。

示例

using System;
namespace Demo {

   class Program {

      static void Main(string[] args) {
         string str = "This is test";
     
         if (str.Contains("test")) {
            Console.WriteLine("Yes, 'test' was found.");
         }
         Console.ReadKey() ;
      }
   }
}
登录后复制

以上就是C# 字符串方法的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:tutorialspoint网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号