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 Environment.NewLine: vbCrLf

Use the Environment.NewLine property for whitespace in a String. NewLine equals \r\n.
Environment.NewLine equals \r\n. In the VB.NET programming language, you can access the Environment.NewLine property. You can alternatively use the vbCrLf value directly. We review this property.
Example. First, we will look at the Environment.NewLine property in a VB.NET program. This property simply returns the string literal equal to vbCrLf, which is equal to "\r\n" in C# and other languages.

Tip: For some programmers, using Environment.NewLine is more descriptive, in that it indicates exactly what it is.

Info: In most cases, there is no functional difference between Environment.NewLine and alternative representations.

VB.NET program that uses Environment.NewLine Module Module1 Sub Main() ' Create two-line string. Dim value As String = "[First" + _ Environment.NewLine + _ "Second]" ' Write to console. Console.WriteLine(value) End Sub End Module Output [First Second]
Example 2. This is another way you can insert a newline into your VB.NET strings. The vbCrLf is a special symbol that is compiled into the string literal "\r\n" as represented in other languages such as the C# language.

Here: We use the & operator on the string literal. Its effect is equivalent to the + operator shown in the first example.

VB.NET program that uses vbCrLf Module Module1 Sub Main() ' Use vbCrLf. Dim value As String = "[First" & vbCrLf & "Second]" ' Write to console. Console.WriteLine(value) End Sub End Module Output [First Second]
IL. You are probably curious what the intermediate language of this program looks like. The vcCrLf is the same as "\r\n" in the C# language. At compile-time, the complete string literal is created and used directly in the program.

Next: This is the relevant instruction from the intermediate language: The string is "\r\n".

IL for vbCrLf L_0001: ldstr "[First\r\nSecond]"
Summary. We dived into newlines. Depending on your preferences, you can either use Environment.NewLine or vbCrLf. For many programmers, the vbCrLf name may seem like Hungarian notation. It does not have full words but instead uses abbreviations.

Note: These developers would be wise to choose Environment.NewLine to preserve their sanity.

© 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