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 Mid Statement

Use the Mid Function to handle substrings. Review the arguments of Mid.
Mid changes a part of a String. It can also return a substring. The Mid statement is particularly useful in VB.NET programs. It makes String instances easier to mutate. We do not need to use Functions such as Substring.
Example. The Mid statement can be used with the name of the variable string you want to change, and positional arguments. In this example, we change the part of the String from the index 5 to the index 8 (length 3). A new String is returned.

Next: We show the Mid function, which simply returns a Substring of the String based on the positional arguments.

VB.NET program that uses Mid statement, function Module Module1 Sub Main() ' Input string. Dim value As String = "The Dev Codes" ' Replace part of string with another string. Mid(value, 5, 3) = "Cat" ' Write. Console.WriteLine(value) ' Get middle part of string. Dim m As String = Mid(value, 5, 3) Console.WriteLine(m) End Sub End Module Output Dot Cat Perls Cat
Implementation. How is the Mid statement implemented? Mid is compiled into the StringType.MidStmtStr subroutine, which internally validates the arguments and then uses a StringBuilder to build up the result.StringBuilder

Function: What about the Mid function? This one is implemented in the obvious way: with the Substring function on the String type.

Substring
As a general rule, when programming in the .NET Framework it is better to use the methods that are readily available to both VB.NET and C# environments. This makes program logic more portable and also understandable for others.
Summary. The Mid statement and Mid function in VB.NET can be useful when you want to mutate a part of a String or get a substring. The Mid statement does not make a string mutable. It provides the appearance of mutation but creates a new copy.
© 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