Net基础篇_学习笔记_第十二天_面向对象继承(字符串_字符串的各种方法)
2024-09-01 15:48:46
我们可以讲字符串看做是char类型的一个只读数组。
ToCharArray();将字符串转换为char数组
new string(char[] chs):能够将char数组转换为字符串
1)、Length:获得当前字符串中字符的个数
2)、ToUpper():将字符转换成大写形式
3)、ToLower():将字符串转换成小写形式
4)、Equals(lessonTwo,StringComparison.OrdinalIgnoreCase):比较两个字符串,可以忽略大小写
5)、Split():分割字符串,返回字符串类型的数组。
6)、Substring():解决字符串。在截取的时候包含要截取的那个位置。
7)、IndexOf():判断某个字符串在字符串中第一次出现的位置,如果没有返回-1、值类型和引用类型在内存上存储的地方不一样。
8)、LastIndexOf():判断某个字符串在字符串中最后一次出现的位置,如果没有同样返回-1
9)、StartsWith():判断以....开始
10)、EndsWith():判断以...结束
11)、Replace():将字符串中某个字符串替换成一个新的字符串
12)、Contains():判断某个字符串是否包含指定的字符串
13)、Trim():去掉字符串中前后的空格
14)、TrimEnd():去掉字符串中结尾的空格
15)、TrimStart():去掉字符串中前面的空格
16)、string.IsNullOrEmpty():判断一个字符串是否为空或者为null
17)、string.Join():将数组按照指定的字符串连接,返回一个字符串。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace 字符串
{
class Program
{
static void Main(string[] args)
{
//练习一:接收用户输入的字符串,将其中的字符以与输入相反的顺序输出。
string str = "abcdefg";
//倒叙循环
//for (int i = str.Length-1; i >=0; i--)
//{
// Console.Write(str[i]);
//}
//Console.ReadKey();
char[] chs=str.ToCharArray();
for (int i = ; i < chs.Length/; i++)
{
char temp = chs[i];
chs[i] = chs[chs.Length--i];
chs[chs.Length - - i] = temp;
}
str = new string(chs);
Console.WriteLine(str);
Console.ReadKey();
}
}
}
using System.Text;
using System.Threading.Tasks; namespace 字符串
{
class Program
{
static void Main(string[] args)
{
//练习一:"hello c sharp"------"sharp c hello"。
string str = "hello c sharp";
string[] strNew=str.Split(new char[] { ' '},StringSplitOptions.RemoveEmptyEntries);
for (int i = ; i < strNew.Length/; i++)
{
string temp = strNew[i];
strNew[i] = strNew[strNew.Length - - i];
strNew[strNew.Length - - i] = temp;
}
for (int i = ; i < strNew.Length; i++)
{
Console.Write(strNew[i]+'\t');
}
Console.ReadKey();
}
}
}
最新文章
- tshark 抓包分析
- mongoDB01 介绍
- KVM虚拟机virsh常用参数
- UISlider
- WindowXP与WIN7环境安装、破解、配置AppScan8.0
- JSP基本语法
- php下载文件的一种方式
- tcp/ip 卷一 读书笔记(1)tcp/ip 概述
- linux利用ssh远程执行多台机器执行同样的命令
- 荣耀7.0系统手机最简单激活Xposed框架的步骤
- Linux之命令进阶
- Arch Linux中使用VMware Workstation不能打开vmmon内核模块
- BZOJ4962 : 简单的字符串
- linux下nodejs的安装
- knn/kmeans/kmeans++/Mini Batch K-means/Affinity Propagation/Mean Shift/层次聚类/DBSCAN 区别
- 后续使用dubbo的必要性的思考
- 【凯子哥带你夯实应用层】使用ActionMode实现有删除动画的多选删除功能
- 两个栈实现队列 Python实现
- win10 uwp 商业游戏
- POJ 3278 Catch That Cow (附有Runtime Error和Wrong Answer的常见原因)