zoukankan      html  css  js  c++  java
  • A.5.2C# 中对字符串(string)的常用处理

    ylbtech- .NET-Basic: A.5.2-C# 中对字符串(string)的常用处理

     A.5.2-C# 中对字符串(string)的常用处理。

    2、基础类 String
    属性: Length:字符串长度
    方法: IndexOf, LastIndexOf,split,replace,substring
    split(字符串),把字符串对象,按指定格式分割为字符数组
    replace(oldString, newString)字符串替换,把字符串对象中的旧的字串替换成为新的字串
    substring(start, length)从字符串对象中截取特定个数的字串
    substring(start),从一个指定的位置开始截取到字符串末尾

    1.A,源代码(Source Code)返回顶部
    using System;
    
    namespace testString
    {
        class Program
        {
            static void Main(string[] args)
            {
                string url = "C://Program Files//CE Remote Tools//5.01//bin//aa.jpg";
    
                Console.WriteLine("长度:{0}",url.Length);
                //从前往后查 a的索引下标
                Console.WriteLine("从前往后查,'a'它的索引小标:{0}",url.IndexOf('a'));
                Console.WriteLine("从后往前查,'a'它的索引小标:{0}", url.LastIndexOf('a'));
    
                string str1 = "yuanbo,xiaomei,chongfei";
                string[] list = str1.Split(',');
                foreach (string a in list)
                {
                    Console.WriteLine(a);
                }
    
                string str2 = "你是小狗。狗";
                Console.WriteLine("用Relpace处理的串:{0}",str2.Replace("","X"));
    
                Console.WriteLine("Substring:{0}", str2.Substring(str2.IndexOf("")));
                Console.WriteLine("Substring:{0}",str2.Substring(0,3));
                Console.ReadLine();
            }
        }
    }
    warn 作者:ylbtech
    出处:http://ylbtech.cnblogs.com/
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    LintCode "Subarray Sum II"
    LintCode "Maximum Subarray Difference"
    LeetCode "Flip Game II"
    LintCode "Sliding Window Median" & "Data Stream Median"
    LintCode "Permutation Index"
    LintCode "Count of Smaller Number before itself"
    LeetCode "Nim Game"
    Etcd在Linux CentOS7下载、安装
    CentOS7 查看开启端口
    CentOS7-防火墙firewall 状态、重启、关闭
  • 原文地址:https://www.cnblogs.com/ylbtech/p/2982966.html
Copyright © 2011-2022 走看看