Strings & Characters

String Datatype is a reference type based on a class
Strings are considered to be reference types ??


System.Environment.NewLine



Initialising

Is there any difference ??

Dim sMyString As String = Nothing 
Dim sMyString As String = ""
Dim sMyString As String




Dim sMyString As String 
sMyString = "my string"

Dim iValue As Integer
iValue = 5
sMyString = iValue.ToString




Padding Strings

Select Case Variable & Microsoft.VisualBasic.Space(20 - Variable.Length) 
   Case "-----------20 chars-------"
   Case "MyVariable---------------"
End Select




Strings must be Initialised

The following line will generate an error:

Dim sTextString As String 
Call MsgBox(sTextString.Length)

All string datatypes must be manually initialised to a zero length string. The best place to do this is when they are declared.

Dim sTextString As String = "" 


Returning the Length of a Constant

String.Copy("some text").Length 


String to Integer

There are two ways you can convert a string representation of a number to an actual numeric datatytpe

Dim sNumber As String = "123" 
Dim iNumber As Integer = System.Convert.Int32(sNumber)

Dim iNumber As Integer = Int32.Parse(sNumber)


Integer to String

Dim i16Number As Int16 
Dim sNumber As String

i16Number = 10
sNumber = i16Number.ToString





© 2017 Better Solutions Limited. All Rights Reserved. © 2017 Better Solutions Limited

Top

Next