zoukankan      html  css  js  c++  java
  • Net基础篇_学习笔记_第十二天_面向对象继承(字符串_字符串的各种方法)

    我们可以讲字符串看做是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():将数组按照指定的字符串连接,返回一个字符串。

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Text;
     5 using System.Threading.Tasks;
     6 
     7 namespace 字符串
     8 {
     9     class Program
    10     {
    11         static void Main(string[] args)
    12         {
    13             //练习一:接收用户输入的字符串,将其中的字符以与输入相反的顺序输出。
    14             string str = "abcdefg";
    15             //倒叙循环
    16             //for (int i = str.Length-1; i >=0; i--)
    17             //{
    18             //    Console.Write(str[i]);
    19             //}
    20             //Console.ReadKey();
    21             char[] chs=str.ToCharArray();
    22             for (int i = 0; i < chs.Length/2; i++)
    23             {
    24                 char temp = chs[i];
    25                 chs[i] = chs[chs.Length-1-i];
    26                 chs[chs.Length - 1 - i] = temp;
    27             }
    28             str = new string(chs);
    29             Console.WriteLine(str);
    30             Console.ReadKey();
    31         }
    32     }
    33 }
     1 using System.Text;
     2 using System.Threading.Tasks;
     3 
     4 namespace 字符串
     5 {
     6     class Program
     7     {
     8         static void Main(string[] args)
     9         {
    10             //练习一:"hello c sharp"------"sharp c hello"。
    11             string str = "hello c sharp";
    12             string[] strNew=str.Split(new char[] { ' '},StringSplitOptions.RemoveEmptyEntries); 
    13             for (int i = 0; i < strNew.Length/2; i++)
    14             {
    15                 string temp = strNew[i];
    16                 strNew[i] = strNew[strNew.Length - 1 - i];
    17                 strNew[strNew.Length - 1 - i] = temp;
    18             }
    19             for (int i = 0; i < strNew.Length; i++)
    20             {
    21                 Console.Write(strNew[i]+'	');
    22             }
    23             Console.ReadKey();
    24         }
    25     }
    26 }
  • 相关阅读:
    rowid去重(转)
    Oracle中 row_number() over()分析函数(转)
    oracle分页计算公式
    vue 生产环境和线上环境配置
    vue postcss 样式等比缩放
    element-ui 表单输入手机号验证是否注册或者存在
    使用vue-qr 生成 二维码
    vue下载excel文件,后台传过来的是文件流解决办法
    前端请求接口发送的路径用域名代替ip
    将本地端口映射子域名
  • 原文地址:https://www.cnblogs.com/NBOWeb/p/7543227.html
Copyright © 2011-2022 走看看