• 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 }
  • 相关阅读:
    计算机进制转换
    十进制二进制转换
    windows XP 下怎样查看系统运行时间总计?
    “编译器错误信息: CS0016: 未能写入输出文件”解决方法
    用ntsd关进程
    Hosts文件的位置
    开机显示client mac addr...... 错误的解决办法 .
    无法嵌入互操作类型“Microsoft.Office.Interop.Excel.ApplicationClass”。请改用适用的接口 .
    【转】XP远程桌面连接2008提示:远程计算机需要网络级别身份验证,而您的计算机不支持该验证 .
    关于Access的郁闷二三事。。。
  • 原文地址:https://www.cnblogs.com/NBOWeb/p/7543227.html
Copyright © 2020-2023  润新知