どうも、ちょげ(@chogetarou)です。
Remove()を使って文字列(string)の先頭から指定した文字数を削除する方法を紹介します。
方法

Remove()を使って文字列(string)の先頭のN文字を削除するには、2つの引数を使います。
まず、文字列からRemove()を呼び出します。
そして、Remove()の第1引数に0、第2引数に削除する文字数を指定します。
//N=削除する文字数
string result = text.Remove(0, N);
上記のRemove()は、呼び出した文字列の先頭からN文字を削除した文字列を返します。
(N=Remove()の第2引数の値)
使用例
using System;
public class Sample{
public static void Main(){
string text = "Python";
string text2 = "Swift";
string text3 = "Kotlin";
string result = text.Remove(0, 2);
string result2 = text2.Remove(0, 3);
string result3 = text3.Remove(0, 4);
System.Console.WriteLine(result);
System.Console.WriteLine(result2);
System.Console.WriteLine(result3);
}
}
出力:
thon
ft
in
コメント