How to resolve the algorithm Repeat a string step by step in the PL/I programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Repeat a string step by step in the PL/I 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 PL/I programming language

Source code in the pl/i programming language

/* To repeat a string a variable number of times: */

s = repeat('ha', 4);

  /* or */

s = copy('ha', 5);

/* To repeat a single character a fixed number of times: */

s = (5)'h';     /* asigns 'hhhhh' to s. */

  

You may also check:How to resolve the algorithm Date manipulation step by step in the 11l programming language
You may also check:How to resolve the algorithm Sorting algorithms/Counting sort step by step in the PL/I programming language
You may also check:How to resolve the algorithm Stirling numbers of the first kind step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm P-value correction step by step in the Ruby programming language
You may also check:How to resolve the algorithm Assertions step by step in the EchoLisp programming language