TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

<< Back to VBNET

VB.NET Remove String

Use the Remove Function on the String type to eliminate characters at an index.
Remove. This Function, part of the String class, makes a String shorter. It eliminates all characters starting at a specified position in the String.
Notes, Remove. With the Remove Function, we can take off any number of characters starting at an index. It is a special form of the Substring() Function.StringsSubstringInsert
First example. We declare a String with some characters on the end we want to remove. Then with LastIndexOf, we find the index of the last space character.LastIndexOf

Here: We call Remove with one argument. This indicates where the string will be stopped.

Tip: All characters following that position are eliminated. This is how a SetLength function on the String type would work.

Length: The Length of the String will always be equal to the argument passed to Remove (if valid).

String Length
VB.NET program that uses Remove function Module Module1 Sub Main() Dim value As String = "bird frog dog" ' Find position of last space. Dim index As Integer = value.LastIndexOf(" "c) ' Remove everything starting at that position. value = value.Remove(index) Console.WriteLine("REMOVE RESULT: {0}", value) End Sub End Module Output REMOVE RESULT: bird frog
Range example. We can specify a count. Only the number of characters specified as the count are removed. Characters following this range are kept in the String.

Argument 1: This is an Integer that indicates the starting index of the range of characters we want to remove.

Argument 2: This is the count of chars (part of the range) we want to remove. It is not an end index.

VB.NET program that uses Remove, range Module Module1 Sub Main() Dim value As String = "abcde" ' Remove 2 chars starting at index 1. Dim removed As String = value.Remove(1, 2) Console.WriteLine("RESULT: {0}", removed) End Sub End Module Output RESULT: ade
Implementation. Remove() with 1 argument calls into Substring() with an argument of 0. Substring specifies the character range to keep, while Remove specifies the range to discard.

Tip: Because of this implementation, it is somewhat faster to directly call the Substring function.

A summary. We used the Remove function. While Substring specifies the characters we want to keep in a new string, Remove specifies the characters we want to discard.
© TheDeveloperBlog.com
The Dev Codes

Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf