Computer Language/C#

[C#] String.Remove 메서드 - 문자열 제거

HONGGG 2023. 8. 14. 05:18

String.Remove

 

문자열에 지정된 범위를 삭제하는 함수

 

 

함수명 String.Remove  
오버로드 Remove(Int32) 지정된 위치부터 마지막까지 모든 문자를 삭제하여 새 문자열을 반환
Remove(Int32, Int32) 지정된 범위 사이 모든 문자를 삭제하여 새 문자열을 반환
반환값 string  

 


Remove(Int32) & Remove(Int32, Int32)

 

using System;

public class HelloWorld
{
	public static void Main()
    {
        string s = "abc---def";
        
        Console.WriteLine("Index: 012345678");
        Console.WriteLine("1)     {0}", s);
        Console.WriteLine("2)     {0}", s.Remove(3));
        Console.WriteLine("3)     {0}", s.Remove(3, 3));
    }
}
Index: 012345678
1)     abc---def
2)     abc
3)     abcdef

 

 


참고자료

 

String.Remove 메서드 (System)

현재 문자열에서 지정한 수의 문자가 삭제되는 새 문자열을 반환합니다.

learn.microsoft.com