473,382 Members | 1,367 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

build string as repeated character

what's the best way in VB.NET to build a string as a concatenation of a
certain number of characters ?

for example, 25 "*" characters :

"*************************"
Nov 20 '05 #1
3 18190
John,
I'm not sure what the "best way" is, however VB.NET offers the following
methods:

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

"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
what's the best way in VB.NET to build a string as a concatenation of a
certain number of characters ?

for example, 25 "*" characters :

"*************************"

Nov 20 '05 #2
I'm finding that PadRight() doesn't work .... do you know why that is ?

Dim s As String
s = "Some text followed by an underline"
s.PadRight(100-s.Length,"_")

s is returned as "Some text followed by an underline"
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:u4**************@tk2msftngp13.phx.gbl...
John,
I'm not sure what the "best way" is, however VB.NET offers the following
methods:

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

"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
what's the best way in VB.NET to build a string as a concatenation of a
certain number of characters ?

for example, 25 "*" characters :

"*************************"


Nov 20 '05 #3
John,
String is immutable, which means you cannot modify the current instance of
the string, hence, PadRight is a function and not a sub.

Try something like

s = s.PadRight(100-s.Length,"_")

However I suspect you want:

s = s.PadRight(100,"_")

As the length to PadRight is the total length of the string, including
existing characters, not the amount to add to the existing string...

Hope this helps
Jay

"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:eD****************@TK2MSFTNGP10.phx.gbl...
I'm finding that PadRight() doesn't work .... do you know why that is ?

Dim s As String
s = "Some text followed by an underline"
s.PadRight(100-s.Length,"_")

s is returned as "Some text followed by an underline"
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message news:u4**************@tk2msftngp13.phx.gbl...
John,
I'm not sure what the "best way" is, however VB.NET offers the following
methods:

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

"John A Grandy" <johnagrandy-at-yahoo-dot-com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
what's the best way in VB.NET to build a string as a concatenation of a certain number of characters ?

for example, 25 "*" characters :

"*************************"



Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: PC Datasheet | last post by:
I need a textbox to be set to a string of 15 Xs. Is there some expression that does something like the following pseudocode: MyTextbox = "X"(15) If there is, can it be done with a multiple...
19
by: Paul | last post by:
hi, there, for example, char *mystr="##this is##a examp#le"; I want to replace all the "##" in mystr with "****". How can I do this? I checked all the string functions in C, but did not...
3
by: Jay Feldman | last post by:
In vb6, the String(Number, Character) function would let you generate a string filled with a certain character. How can I do this in .NET, since there is no String function and I had trouble...
3
by: Erick Sasse | last post by:
This is not really a C# question, but I'm not sure which is the best group to post it. Please, point me to the right one. What's the best way to create a string from a repeated char? For...
20
by: John Salerno | last post by:
Here's the code I wrote: file = open('C:\switches.txt', 'r') switches = file.readlines() i = 0 for line in switches: line = switches i += 1
14
by: Hugh Janus | last post by:
Hi all, I have several *long* strings (see bottom of post for an example) which I will be sending across a network. Therefore, I want to compress them for speed and because later they will be...
24
by: garyusenet | last post by:
I'm working on a data file and can't find any common delimmiters in the file to indicate the end of one row of data and the start of the next. Rows are not on individual lines but run accross...
2
by: rn5a | last post by:
All the String functions like 'Len', 'Left', 'Right', 'Mid' etc. that are available in ASP are supported by ASP.NET as well except for the string function 'String'. The 'String' function takes...
6
by: Faheem Mitha | last post by:
Hi everybody, I was wondering if anyone can explain this. My understanding is that 'is' checks if the object is the same. However, in that case, why this inconsistency for short strings? I would...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.