C# 属性

C# 抽象

C# 字符串

C# 泛型

C# 杂项

C# 新特性

C# Remove() 删除字符串

C# Remove() 方法用于在从指定的 beginIndex 删除所有字符直到给定长度后获取新字符串。如果未指定长度,则删除 beginIndex 之后的所有字符。

签名

句法 (Syntax)

public string Remove(Int32 beginIndex)  
public string Remove(Int32 beginIndex, Int32 length)

范围

index:整数类型参数。

返回

它返回一个字符串。


C# String Remove() 方法示例

例子 (Example)

using System;   
    public class StringExample    
    {    
        public static void Main(string[] args)    
        {    
           string s1 = "Hello C#";  
           string s2 = s1.Remove(2);  
           Console.WriteLine(s2);  
       }    
    }

输出:

He

C# String Remove() 方法示例 2

例子 (Example)

using System;   
    public class StringExample    
    {    
        public static void Main(string[] args)    
        {    
        string s1 = "abcdefghijk";  
        string s2 = s1.Remove(4, 5);  
        Console.WriteLine(s2);  
       }    
    }

输出:

abcdjk


  • 使用社交账号登录,本站支持
全部评论(0)