String.Remove 메서드

정의

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

오버로드

Remove(Int32)

지정된 위치부터 마지막 위치 사이에 현재 인스턴스의 모든 문자가 삭제되었던 새 문자열을 반환합니다.

Remove(Int32, Int32)

현재 인스턴스의 지정된 위치에서 시작하여 지정된 수의 문자가 삭제되었던 새 문자열을 반환합니다.

Remove(Int32)

Source:
String.Manipulation.cs
Source:
String.Manipulation.cs
Source:
String.Manipulation.cs

지정된 위치부터 마지막 위치 사이에 현재 인스턴스의 모든 문자가 삭제되었던 새 문자열을 반환합니다.

public:
 System::String ^ Remove(int startIndex);
public string Remove (int startIndex);
member this.Remove : int -> string
Public Function Remove (startIndex As Integer) As String

매개 변수

startIndex
Int32

문자 삭제를 0부터 시작할 위치입니다.

반환

제거된 문자를 제외하고 이 문자열과 동일한 새 문자열입니다.

예외

startIndex가 0보다 작은 경우

또는

startIndex이(가) 이 문자열 내에 없는 위치를 지정합니다.

예제

다음 예제는 Remove 메서드. 다음 대/소문자를 지정한 인덱스에서 문자열의 끝까지 시작하는 모든 텍스트를 제거합니다. 마지막 사례는 지정된 인덱스에서 시작하는 세 문자를 제거합니다.

// This example demonstrates the String.Remove() method.
using namespace System;
int 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 ) );
}

/*
This example produces the following results:

Index: 012345678
1)     abc---def
2)     abc
3)     abcdef

*/
// This example demonstrates the String.Remove() method.
using System;

class Sample
{
    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));
    }
}
/*
This example produces the following results:

Index: 012345678
1)     abc---def
2)     abc
3)     abcdef

*/
// This example demonstrates the String.Remove() method.
let s = "abc---def"

printfn "Index: 012345678"
printfn $"1)     {s}"
printfn $"2)     {s.Remove 3}"
printfn $"3)     {s.Remove(3, 3)}"
(*
This example produces the following results:

Index: 012345678
1)     abc---def
2)     abc
3)     abcdef

*)
' This example demonstrates the String.Remove() method.
Class Sample
   Public Shared Sub Main()
      Dim s As String = "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))
   End Sub
End Class
'
'This example produces the following results:
'
'Index: 012345678
'1)     abc---def
'2)     abc
'3)     abcdef
'

설명

.NET Framework 문자열은 0부터 시작합니다. 매개 변수의 startIndex 값은 문자열 인스턴스의 길이보다 0에서 1까지 다양할 수 있습니다.

참고

이 메서드는 현재 인스턴스의 값을 수정하지 않습니다. 대신 원래 문자열의 위치에서 startIndex 끝까지 모든 문자가 제거된 새 문자열을 반환합니다.

추가 정보

적용 대상

Remove(Int32, Int32)

Source:
String.Manipulation.cs
Source:
String.Manipulation.cs
Source:
String.Manipulation.cs

현재 인스턴스의 지정된 위치에서 시작하여 지정된 수의 문자가 삭제되었던 새 문자열을 반환합니다.

public:
 System::String ^ Remove(int startIndex, int count);
public string Remove (int startIndex, int count);
member this.Remove : int * int -> string
Public Function Remove (startIndex As Integer, count As Integer) As String

매개 변수

startIndex
Int32

문자 삭제를 0부터 시작할 위치입니다.

count
Int32

삭제할 문자의 수입니다.

반환

제거된 문자를 제외하고 이 인스턴스와 동일한 새 문자열입니다.

예외

startIndex 또는 count이(가) 0보다 작습니다.

또는

startIndex과(와) count이(가) 함께 사용되어 이 인스턴스 외부 위치를 지정합니다.

예제

다음 예제에서는 전체 이름에서 중간 이름을 제거하는 방법을 보여 줍니다.

using namespace System;
int main()
{
   String^ name = "Michelle Violet Banks";
   Console::WriteLine( "The entire name is '{0}'", name );
   
   // remove the middle name, identified by finding the spaces in the middle of the name->->.
   int foundS1 = name->IndexOf( " " );
   int foundS2 = name->IndexOf( " ", foundS1 + 1 );
   if ( foundS1 != foundS2 && foundS1 >= 0 )
   {
      name = name->Remove( foundS1 + 1, foundS2 - foundS1 );
      Console::WriteLine( "After removing the middle name, we are left with '{0}'", name );
   }
}
// The example displays the following output:
//       The entire name is 'Michelle Violet Banks'
//       After removing the middle name, we are left with 'Michelle Banks'
using System;

public class RemoveTest
{
    public static void Main()
    {

        string name = "Michelle Violet Banks";

        Console.WriteLine("The entire name is '{0}'", name);

        // Remove the middle name, identified by finding the spaces in the name.
        int foundS1 = name.IndexOf(" ");
        int foundS2 = name.IndexOf(" ", foundS1 + 1);

        if (foundS1 != foundS2 && foundS1 >= 0)
        {
            name = name.Remove(foundS1 + 1, foundS2 - foundS1);

            Console.WriteLine("After removing the middle name, we are left with '{0}'", name);
        }
    }
}
// The example displays the following output:
//       The entire name is 'Michelle Violet Banks'
//       After removing the middle name, we are left with 'Michelle Banks'
let name = "Michelle Violet Banks"

printfn $"The entire name is '{name}'"

// Remove the middle name, identified by finding the spaces in the name.
let foundS1 = name.IndexOf " "
let foundS2 = name.IndexOf(" ", foundS1 + 1)

if foundS1 <> foundS2 && foundS1 >= 0 then
    let name = name.Remove(foundS1 + 1, foundS2 - foundS1)

    printfn $"After removing the middle name, we are left with '{name}'"
// The example displays the following output:
//       The entire name is 'Michelle Violet Banks'
//       After removing the middle name, we are left with 'Michelle Banks'
Public Class RemoveTest
    
    Public Shared Sub Main()
        Dim name As String = "Michelle Violet Banks"
                
        Console.WriteLine("The entire name is '{0}'", name)
        Dim foundS1 As Integer = name.IndexOf(" ")
        Dim foundS2 As Integer = name.IndexOf(" ", foundS1 + 1)
        If foundS1 <> foundS2 And foundS1 >= 0 Then
            
            ' remove the middle name, identified by finding the spaces in the middle of the name...    
            name = name.Remove(foundS1 + 1, foundS2 - foundS1)
            
            Console.WriteLine("After removing the middle name, we are left with '{0}'", name)
        End If
    End Sub
End Class 
' The example displays the following output:
'       The entire name is 'Michelle Violet Banks'
'       After removing the middle name, we are left with 'Michelle Banks'

설명

.NET Framework 문자열은 0부터 시작합니다. 매개 변수의 startIndex 값은 문자열 인스턴스의 길이보다 0에서 1까지 다양할 수 있습니다.

참고

이 메서드는 현재 인스턴스의 값을 수정하지 않습니다. 대신 매개 변수로 지정된 문자 수가 제거된 새 문자열을 count 반환합니다. 문자는 로 지정된 위치에서 제거됩니다 startIndex.

추가 정보

적용 대상