473,382 Members | 1,389 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.

Is there a repeat characters function?

Hi Everyone:

I know that I can repeat a single character using the StrDup function. Is
there a function that will allow me to repeat a string? StrDup(5,"John")
returns "JJJJJ." Is there a function (or workaround) that will
return"JohnJohnJohnJohnJohn"?

Thanks in advance.

John

--
John L. Whelan
College Librarian
College of the North Atlantic
Grand Falls-Windsor, NL
Aug 17 '06 #1
5 10310
John,

Even if it did exist I would do it in this way

dim John as String
For i as integer = 0 to 4
John += "John"
Next

(And if it exist you can be sure that it is done internal the same)

I would not take the time to search

Cor

"John L. Whelan" <Jo*********@cna.nl.caschreef in bericht
news:81**********************************@microsof t.com...
Hi Everyone:

I know that I can repeat a single character using the StrDup function. Is
there a function that will allow me to repeat a string? StrDup(5,"John")
returns "JJJJJ." Is there a function (or workaround) that will
return"JohnJohnJohnJohnJohn"?

Thanks in advance.

John

--
John L. Whelan
College Librarian
College of the North Atlantic
Grand Falls-Windsor, NL

Aug 17 '06 #2

John L. Whelan napisal(a):
Hi Everyone:

I know that I can repeat a single character using the StrDup function. Is
there a function that will allow me to repeat a string? StrDup(5,"John")
returns "JJJJJ." Is there a function (or workaround) that will
return"JohnJohnJohnJohnJohn"?

Thanks in advance.

John
Hi,

I don't know such a function but I wrote for you one:

Private Function Repeat(ByVal StringToRepeat As String, ByVal
HowManyTimes As Integer)
Dim Result As String = ""
For i As Integer = 1 To HowManyTimes
Result += StringToRepeat
Next
Return Result
End Function

Hope this helps,
sweet_dreams

Aug 17 '06 #3
Don't think there is a built in way, but it's not so hard to build a
function that does it. Try this:

Public Function StrDup(ByVal count As Integer, ByVal value As String) As
String
Dim sb As New System.Text.StringBuilder
While count 0
sb.Append(value)
count -= 1
End While
Return sb.ToString()
End Function

/claes

"John L. Whelan" <Jo*********@cna.nl.cawrote in message
news:81**********************************@microsof t.com...
Hi Everyone:

I know that I can repeat a single character using the StrDup function. Is
there a function that will allow me to repeat a string? StrDup(5,"John")
returns "JJJJJ." Is there a function (or workaround) that will
return"JohnJohnJohnJohnJohn"?

Thanks in advance.

John

--
John L. Whelan
College Librarian
College of the North Atlantic
Grand Falls-Windsor, NL

Aug 17 '06 #4
John L. Whelan wrote:
Hi Everyone:

I know that I can repeat a single character using the StrDup
function. Is there a function that will allow me to repeat a string?
StrDup(5,"John") returns "JJJJJ." Is there a function (or workaround)
that will return"JohnJohnJohnJohnJohn"?
I can do this!

Dim s As String
s = StrDup(5, "x")
s = s.Replace("x", "John")

Or for a longer string:-

Dim b As New StringBuilder
b.Append("x", 500)
b.Replace("x", "John")

Andrew
Aug 17 '06 #5
Claes (and Andrew),
I would recommend setting the capacity of the StringBuilder when you create
it, this will prevent any intermediate reallocations of its internal buffer.
Especially in this case where you have a clear indication of how large the
final string will be.

| Dim sb As New System.Text.StringBuilder(count * value.Length)

The "count * value.Length" causes the StringBuilder to allocate a "count *
value.Length" character buffer.

Remember that New StringBuilder() allocates a 16 character buffer, which it
then doubles each time it (the buffer) needs to be expanded.

If you want "John" duplicated 500 times, StringBuilder will need to
reallocate its buffer a number of a significant # of times. These
reallocations can cause a performance problem in that the buffer itself
needs to be copied each time it is reallocated, plus each old buffer will
add pressure to the GC...

In cases where I don't have a clear indication of how large the final string
will be I try to use a guesstimate. For example the average/typical length
of the final string.
--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Claes Bergefall" <lo*****@nospam.nospamwrote in message
news:uX**************@TK2MSFTNGP05.phx.gbl...
| Don't think there is a built in way, but it's not so hard to build a
| function that does it. Try this:
|
| Public Function StrDup(ByVal count As Integer, ByVal value As String) As
| String
| Dim sb As New System.Text.StringBuilder
| While count 0
| sb.Append(value)
| count -= 1
| End While
| Return sb.ToString()
| End Function
|
| /claes
|
| "John L. Whelan" <Jo*********@cna.nl.cawrote in message
| news:81**********************************@microsof t.com...
| Hi Everyone:
| >
| I know that I can repeat a single character using the StrDup function.
Is
| there a function that will allow me to repeat a string? StrDup(5,"John")
| returns "JJJJJ." Is there a function (or workaround) that will
| return"JohnJohnJohnJohnJohn"?
| >
| Thanks in advance.
| >
| John
| >
| --
| John L. Whelan
| College Librarian
| College of the North Atlantic
| Grand Falls-Windsor, NL
|
|
Aug 20 '06 #6

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

Similar topics

5
by: Raterus | last post by:
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...
11
by: Ron L | last post by:
I have a barcode scanner which uses a "keyboard wedge" program so that the data it scans comes through as if it was typed on a keyboard. I am trying to have the data in the barcode be displayed in...
8
by: Csaba Gabor | last post by:
I wrote a .repeat(n) function for strings which seemed to work fine: String.prototype.repeat = function(n) { // repeats the string n times if (n<1) return ""; if (n<2) return this; for (var...
0
by: Josha | last post by:
Hi, I am new to VB and still getting a handle on things. How do I repeat the below code for each new odd numbered page. If this requires the use of line numbers instead of paragraph numbers to set...
3
by: Jana | last post by:
Good morning, Access gurus! I'm having a brain fart and can't seem to wrap my head around the logic for this problem, so I'm hoping someone out there can help me out. Here's my situation: I...
4
by: Tom | last post by:
Hi: I'm having a problem with a simple report in a simple database. Basically it's an issue tracking database - what is the issue, what is the proposed solution, who is responsible, a tracking...
3
by: Sergei Shelukhin | last post by:
Can someone tell me why does IE 6 ignore no-repeat and repeat bg image twice in the following page? I tried adding it to container div instead of form, but it is till repeated exactly twice. With...
7
by: =?Utf-8?B?cmF1bGF2aQ==?= | last post by:
Hi: vs2008 c# Having a string myvar = "*"; I need to repeat this myvar 100 times when is used at run time... string myline = myvar + myvar+ myvar....(100 times) What the easiest way to...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.