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 }
  • 相关阅读:
    笔记35 跨重定向请求传递数
    判断邮箱的正则表达式
    按钮
    async await 的用法
    笔记34 Spring MVC的高级技术——处理multipart形式的数据
    Convert Sorted Array to Binary Search Tree
    Binary Tree Zigzag Level Order Traversal
    Unique Binary Search Trees,Unique Binary Search Trees II
    Validate Binary Search Tree
    Populating Next Right Pointers in Each Node,Populating Next Right Pointers in Each Node II
  • 原文地址:https://www.cnblogs.com/NBOWeb/p/7543227.html
Copyright © 2011-2022 走看看