In VB6 I could create a string using the string word
Does anyone know the equivalent for VB.NETVB Code:
string(53,'#')
Thanks
Printable View
In VB6 I could create a string using the string word
Does anyone know the equivalent for VB.NETVB Code:
string(53,'#')
Thanks
Perhaps something like:
Dim str As String = ""
str = str.PadRight(53, "#"c)
This is a single line example
VB Code:
Dim sValue As New String("#"c, 53)
I didn't know this method. Good to know!:)
Thats really strange because when I tried typing a variable declaration like that and typed the open bracket the intellisence didn't kick in.Quote:
Originally posted by CyberHawke
This is a single line example
VB Code:
Dim sValue As New String("#"c, 53)
I have just tried it now and it did.
I was sure there was some kind of feature like that somewhere.
Many Thanks.
probably because "Intelisense" should be renamed to "Intelinonsense" :p
OK. That works fine, but can you tell me why it needs "New"? (I know it does)Quote:
Originally posted by CyberHawke
This is a single line example
VB Code:
Dim sValue As New String("#"c, 53)
What is the difference between:
Dim strTest As New String
and
Dim strTest As String
(I have both Option Strict and Option Explicit set to On.)
Ok, you need to understand that in .NET "EVERYTHING" is an object, even datatypes. so when you declare an instance variable of type String, just as with any other object, you need to instantiate it by declaring it as new. This is only true when you are doing an initial population of the string with a repeating set of characters. In all other instances, VB will set the object reference for you automatically, one of the reasons that VB developers have been shunned by the rest of the developer community for so many years and also why VB has been labeled a "toy" language in the past.
Hi cyberhawke,
Many thanks.
By the way, if VB has been described as a "Toy language" I wonder what the comment is about my learning ground -
dBase III plus?:eek:
VB was described as a "Toy Language" in the past by C/C++ developers and such because it wrapped most of the low-level work that they had to do by hand. While with .NET much of that is still true, you do have more access to low-level functions as well as full access to full OOP development and multi-threading. With the advent of VB.NET, it is no longer considered a toy language.