Repeat character x number of times

  • Thread starter Thread starter Raterus
  • Start date Start date
R

Raterus

I think I've seen this before as a built-in function. I need a function that I pass it a character and a number and it returns that character repeated that many times. Easy enough to do myself, I just thought I remember a built-in function that did this? Does it exist?

Thanks,
--Michael
 
New String(" ",10)


--
OHM ( Terry Burns ) * Use the following to email me *

Dim ch() As Char = "ufssz/cvsotAhsfbuTpmvujpotXjui/OFU".ToCharArray()
For i As Int32 = 0 To ch.Length - 1
ch(i) = Convert.ToChar(Convert.ToInt16(ch(i)) - 1)
Next
Process.Start("mailto:" & New String(ch))
--


I think I've seen this before as a built-in function. I need a function
that I pass it a character and a number and it returns that character
repeated that many times. Easy enough to do myself, I just thought I
remember a built-in function that did this? Does it exist?

Thanks,
--Michael
 
Raterus,
In addition to the other comments.

You can use:

System.String.New(Char, Integer)

Dim str As String
str = New String("x"c, 5)


Microsoft.VisualBasic.StrDup(Integer, Char)

Microsoft.VisualBasic.StrDup(Integer, Object)

Microsoft.VisualBasic.StrDup(Integer, String)

str = StrDup(5, "x"c)
str = StrDup(5, "xx")


System.String.PadLeft(Integer, Char)

System.String.PadRight(Integer, Char)

str = String.Empty.PadLeft(5, "x"c)

I normally use the first one, the StrDup is the String function from VB6.

The last two requires an existing string, so I normally would not use them
for this per se, I would use them when I needed to pad an existing string to
a certain number of characters...

Hope this helps
Jay


I think I've seen this before as a built-in function. I need a function
that I pass it a character and a number and it returns that character
repeated that many times. Easy enough to do myself, I just thought I
remember a built-in function that did this? Does it exist?

Thanks,
--Michael
 
Raterus said:
I think I've seen this before as a built-in function. I need a function
that I pass it a character and a number and it returns that character
repeated that many times. Easy enough to do myself, I just thought I
remember a built-in function that did this? Does it exist?

Thanks,
--Michael


You are thinking of VB6's String() function:

String(7,65) '<-- creates string of 7 A's

AFAIK, there is not an eqivalent in the string class of VB.NET.
 
DenBorg,
Please read my previous post:
AFAIK, there is not an eqivalent in the string class of VB.NET.

VB6's string function is StrDup in VB.NET. You can also use the String
Constructor, samples are included in my previous post on this thread.

Hope this helps
Jay
 
Jay B. Harlow said:
VB6's string function is StrDup in VB.NET. You can also use the String
Constructor, samples are included in my previous post on this thread.

That is very helpful to know. Thank you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top