How to resolve the algorithm Repeat a string step by step in the Visual Basic programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Repeat a string step by step in the Visual Basic programming language
Table of Contents
Problem Statement
Take a string and repeat it some number of times.
Example: repeat("ha", 5) => "hahahahaha"
If there is a simpler/more efficient way to repeat a single “character” (i.e. creating a string filled with a certain character), you might want to show that as well (i.e. repeat-char("*", 5) => "*****").
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Repeat a string step by step in the Visual Basic programming language
Source code in the visual programming language
Public Function StrRepeat(s As String, n As Integer) As String
Dim r As String, i As Integer
r = ""
For i = 1 To n
r = r & s
Next i
StrRepeat = r
End Function
Debug.Print StrRepeat("ha", 5)
Public Function StrRepeat(sText As String, n As Integer) As String
StrRepeat = Replace(String(n, "*"), "*", sText)
End Function
Debug.Print String(5, "x")
You may also check:How to resolve the algorithm Zeckendorf number representation step by step in the Standard ML programming language
You may also check:How to resolve the algorithm Klarner-Rado sequence step by step in the C++ programming language
You may also check:How to resolve the algorithm Price fraction step by step in the J programming language
You may also check:How to resolve the algorithm Egyptian division step by step in the Julia programming language
You may also check:How to resolve the algorithm Knapsack problem/Bounded step by step in the OOCalc programming language