String.Remove Метод
Определение
Возвращает новую строку, в которой удалено указанное число знаков текущей строки.Returns a new string in which a specified number of characters from the current string are deleted.
Перегрузки
Remove(Int32) |
Возвращает новую строку, в которой были удалены все символы, начиная с указанной позиции и до конца в текущем экземпляре.Returns a new string in which all the characters in the current instance, beginning at a specified position and continuing through the last position, have been deleted. |
Remove(Int32, Int32) |
Возвращает новую строку, в которой было удалено указанное число символов в указанной позиции.Returns a new string in which a specified number of characters in the current instance beginning at a specified position have been deleted. |
Remove(Int32)
Возвращает новую строку, в которой были удалены все символы, начиная с указанной позиции и до конца в текущем экземпляре.Returns a new string in which all the characters in the current instance, beginning at a specified position and continuing through the last position, have been deleted.
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
Отсчитываемая от нуля позиция, с которой начинается удаление знаков.The zero-based position to begin deleting characters.
Возвращаемое значение
Новая строка, эквивалентная данной строке за минусом удаленных знаков.A new string that is equivalent to this string except for the removed characters.
Исключения
Значение параметра startIndex
меньше нуля.startIndex
is less than zero.
-или--or-
startIndex
указывает положение, которое находится за пределами этой строки.startIndex
specifies a position that is not within this string.
Примеры
В следующем примере демонстрируется Remove метод.The following example demonstrates the Remove method. В этом случае весь текст, начиная с указанного индекса, удаляется с конца строки.The next-to-last case removes all text starting from the specified index through the end of the string. В последнем случае удаляются три символа, начиная с указанного индекса.The last case removes three characters starting from the specified index.
// 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.
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.NET Framework от нуля.In the .NET Framework.NET Framework, strings are zero-based. Значение startIndex
параметра может находиться в диапазоне от нуля до значения, меньшего, чем длина экземпляра строки.The value of the startIndex
parameter can range from zero to one less than the length of the string instance.
Примечание
Этот метод не изменяет значение текущего экземпляра.This method does not modify the value of the current instance. Вместо этого возвращается новая строка, в которой удаляются все символы, начиная с startIndex
конца исходной строки.Instead, it returns a new string in which all characters from position startIndex
to the end of the original string have been removed.
См. также раздел
- Int32
- Concat(Object)
- Insert(Int32, String)
- Join(String, String[])
- Replace(Char, Char)
- Split(Char[])
- Substring(Int32)
- Trim(Char[])
Применяется к
Remove(Int32, Int32)
Возвращает новую строку, в которой было удалено указанное число символов в указанной позиции.Returns a new string in which a specified number of characters in the current instance beginning at a specified position have been deleted.
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
Отсчитываемая от нуля позиция, с которой начинается удаление знаков.The zero-based position to begin deleting characters.
- count
- Int32
Число символов для удаления.The number of characters to delete.
Возвращаемое значение
Новая строка, эквивалентная данному экземпляру за минусом удаленных знаков.A new string that is equivalent to this instance except for the removed characters.
Исключения
Значение параметра startIndex
или count
меньше нуля.Either startIndex
or count
is less than zero.
-или--or-
startIndex
плюс count
указывает позицию за пределами этого экземпляра.startIndex
plus count
specify a position outside this instance.
Примеры
В следующем примере показано, как можно удалить отчество из полного имени.The following example demonstrates how you can remove the middle name from a complete name.
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 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'
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.NET Framework от нуля.In the .NET Framework.NET Framework, strings are zero-based. Значение startIndex
параметра может находиться в диапазоне от нуля до значения, меньшего, чем длина экземпляра строки.The value of the startIndex
parameter can range from zero to one less than the length of the string instance.
Примечание
Этот метод не изменяет значение текущего экземпляра.This method does not modify the value of the current instance. Вместо этого он возвращает новую строку, в которой было удалено количество символов, указанное в count
параметре.Instead, it returns a new string in which the number of characters specified by the count
parameter have been removed. Символы удаляются в позиции, указанной в параметре startIndex
.The characters are removed at the position specified by startIndex
.
См. также раздел
- Int32
- Concat(Object)
- Insert(Int32, String)
- Join(String, String[])
- Replace(Char, Char)
- Split(Char[])
- Substring(Int32)
- Trim(Char[])