欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > > 文章正文

C#截取字符串(String.Substring 方法 ),

来源: javaer 分享于  点击 8813 次 点评:29

C#截取字符串(String.Substring 方法 ),


 

String.Substring 方法

名称 说明
String.Substring (Int32) 从此实例检索子字符串。子字符串从指定的字符位置开始。
String.Substring (Int32, Int32) 从此实例检索子字符串。子字符串从指定的字符位置开始且具有指定的长度。

举例如下:

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string s = "Hello C# World!";
            //s1为从s中截取的位置为3的字符以后的字符子串,3表示子字符串的起始字符位置
            string s1=s.Substring(3);
            Console.WriteLine(s1);
            //s2为从s中截取的位置为6的字符开始长度为2的字符串,6表示子字符的起始字符位置,2表示子字符长度
            string s2 = s.Substring(6, 2);
            Console.WriteLine(s2);
        }
    }
}
结果如下:

lo C# World!

C#

相关文章

    暂无相关文章

用户点评