Is String() Function Gone?

  • Thread starter Thread starter TC
  • Start date Start date
T

TC

Visual Basic used to have a function called String(), which would create a
repeating character string. Is that gone in VB .NET?

-TC
 
TC,

Take a look as string.PadLeft and string.PadRight

These two functions replace the old String() functions

Kirk Graves
 
Hi,

Yes the string function is gone. You can however create a new
string with repeating characters.

Dim strC As String

strC= new String("C",10) ' New string CCCCCCCCCC

Me.Text = strC

Ken
 
TC said:
Visual Basic used to have a function called String(), which would
create a repeating character string. Is that gone in VB .NET?

s = new string("x"c, 20)
 
TC,
I would recommend Ken's example

Dim strC As String

strC= new String("C"c,10) ' New string CCCCCCCCCC

Me.Text = strC

Note if you are using Option Strict On (you are using Option Strict On
correct!), you will need to specify a Char literal as opposed to a String
Literal. A Char literal looks like a String literal only it has a lower case
c on the end.

"A"c is a char literal
"A" is a string literal.

There is also the StrDup function found in the Microsoft.VisualBasic.Strings
module that you can use to create the string.

strC = StrDup(10, "C"c)
strC = StrDup(10, "C")

Dim obj As Object = "C"
obj = StrDup(10, obj)

Which is overloaded for Char, String and Object, so its more forgiving with
Option Strict On. Note the Object overload returns an Object, however the
parameter still needs to contain a String or Char.

Hope this helps
Jay
 
TC said:
Visual Basic used to have a function called String(), which would create a
repeating character string. Is that gone in VB .NET?

The function has been renamed to 'StrDup'.
 
Back
Top