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 }
  • 相关阅读:
    解决 搭建Jekins过程中 启动Tomcat的java.net.UnknownHostException异常
    射手和农场主
    java 和 JS(javaScript)中的反斜杠正则转义
    分享修改密码的SharePoint Web part: ITaCS Change Password web part
    分享微软官方Demo用的SharePoint 2010, Exchange 2010, Lync 2010虚拟机
    Office 365 的公共网站的一些限制及解决的办法
    SharePoint 2013 关闭 customErrors
    安装 KB2844286 导致SharePoint 2010 XSLT web part 显示出现错误
    安装Office Web Apps Server 2013 – KB2592525安装失败
    如何将hyper-v虚拟机转换成vmware的虚拟机- 转换SharePoint 2010 Information Worker Demonstration and Evaluation Virtual Machine (SP1)
  • 原文地址:https://www.cnblogs.com/NBOWeb/p/7543227.html
Copyright © 2011-2022 走看看