How to replicate a character


Hello group,

Unfortunately I'm not a VB.net developer but I am reviewing somebody's code where has something like:

WriteAllText("file_name", " ********************************  ", True)

Is there a better way to replicate the * character like replicate or duplicate("*") as argument in the function.

Thanks,
ak

akohanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

käµfm³d 👽Commented:
You could do where 10 is the total number of *'s:
String.Empty.PadRight(10, "*"c)

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
käµfm³d 👽Commented:
Alternatively
"".PadRight(10, "*"c)
 
  --OR--
 
"".PadLeft(10, "*"c)

Open in new window

0
Todd MummertCommented:
0
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Mike TomlinsonMiddle School Assistant TeacherCommented:
...and another one:

        Dim stars As New String("*", 32)
        MessageBox.Show(stars)
0
akohanAuthor Commented:


May I ask what is the small "c" character at the end of "*" ?

like  "*"c

Thanks.
0
Mike TomlinsonMiddle School Assistant TeacherCommented:
That converts the String "*" to a Char.

It's not actually necessary for this function as it accepts "any valid Char, String, or Object expression."

It's really on necessary when "Option Strict" is on....since otherwise the implicit conversion is done for you.  You see it more often in C# where the default typecasting is more strict and it's required.
0
akohanAuthor Commented:


Thank you!
0
akohanAuthor Commented:


Thanks to all.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.