String.Remove Metodo
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Restituisce una nuova stringa in cui viene eliminato un numero specificato di caratteri dalla stringa corrente.
Overload
| Nome | Descrizione |
|---|---|
| Remove(Int32, Int32) |
Restituisce una nuova stringa in cui è stato eliminato un numero specificato di caratteri nell'istanza corrente a partire da una posizione specificata. |
| Remove(Int32) |
Restituisce una nuova stringa in cui tutti i caratteri dell'istanza corrente, a partire da una posizione specificata e continuando fino all'ultima posizione, sono stati eliminati. |
Remove(Int32, Int32)
- Origine:
- String.Manipulation.cs
- Origine:
- String.Manipulation.cs
- Origine:
- String.Manipulation.cs
- Origine:
- String.Manipulation.cs
- Origine:
- String.Manipulation.cs
Restituisce una nuova stringa in cui è stato eliminato un numero specificato di caratteri nell'istanza corrente a partire da una posizione specificata.
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
Parametri
- startIndex
- Int32
Posizione in base zero per iniziare a eliminare i caratteri.
- count
- Int32
Numero di caratteri da eliminare.
Valori restituiti
Nuova stringa equivalente a questa istanza, ad eccezione dei caratteri rimossi.
Eccezioni
startIndex O count è minore di zero.
oppure
startIndex e count specificare una posizione all'esterno di questa istanza.
Esempio
Nell'esempio seguente viene illustrato come rimuovere il secondo nome da un nome completo.
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'
Commenti
In .NET Framework le stringhe sono basate su zero. Il valore del startIndex parametro può variare da zero a uno minore della lunghezza dell'istanza di stringa.
Note
Questo metodo non modifica il valore dell'istanza corrente. Restituisce invece una nuova stringa in cui il numero di caratteri specificato dal count parametro è stato rimosso. I caratteri vengono rimossi nella posizione specificata da startIndex.
Vedi anche
- Int32
- Concat(Object)
- Insert(Int32, String)
- Join(String, String[])
- Replace(Char, Char)
- Split(Char[])
- Substring(Int32)
- Trim(Char[])
Si applica a
Remove(Int32)
- Origine:
- String.Manipulation.cs
- Origine:
- String.Manipulation.cs
- Origine:
- String.Manipulation.cs
- Origine:
- String.Manipulation.cs
- Origine:
- String.Manipulation.cs
Restituisce una nuova stringa in cui tutti i caratteri dell'istanza corrente, a partire da una posizione specificata e continuando fino all'ultima posizione, sono stati eliminati.
public:
System::String ^ Remove(int startIndex);
public string Remove(int startIndex);
member this.Remove : int -> string
Public Function Remove (startIndex As Integer) As String
Parametri
- startIndex
- Int32
Posizione in base zero per iniziare a eliminare i caratteri.
Valori restituiti
Nuova stringa equivalente a questa stringa, ad eccezione dei caratteri rimossi.
Eccezioni
startIndex è minore di zero.
oppure
startIndex è maggiore della lunghezza di questa istanza.
Esempio
Nell'esempio seguente viene illustrato il Remove metodo . Il case successivo all'ultimo rimuove tutto il testo a partire dall'indice specificato fino alla fine della stringa. L'ultimo case rimuove tre caratteri a partire dall'indice specificato.
// 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
'
Commenti
In .NET Framework le stringhe sono basate su zero. Il valore del startIndex parametro può variare da zero alla lunghezza dell'istanza di stringa.
Note
Questo metodo non modifica il valore dell'istanza corrente. Restituisce invece una nuova stringa in cui sono stati rimossi tutti i caratteri dalla posizione startIndex alla fine della stringa originale.
Vedi anche
- Int32
- Concat(Object)
- Insert(Int32, String)
- Join(String, String[])
- Replace(Char, Char)
- Split(Char[])
- Substring(Int32)
- Trim(Char[])