### Bookstore

 Computer Math and Games in Pascal (preview) Lazarus Handbook

### Author Topic: Is there a lazarus function f('a',3) = 'aaa' ?  (Read 1946 times)

#### gabriel

• Newbie
• Posts: 4
##### Is there a lazarus function f('a',3) = 'aaa' ?
« on: July 14, 2021, 10:31:09 am »
I have been looking in documentation to find a simple function, that takes a string s and number n as arguments. The result should be the string s repeated n times.

f('a',3) should give the result 'aaa'.

Of cause I can easily write a function myself. I don't need help for that. But I am sure Lazarus/Freepascal has  a ready made function, but I just can't find it.

If you have a clue please let me know.

gabriel

#### marcov

• Hero Member
• Posts: 9534
• FPC developer.
##### Re: Is there a lazarus function f('a',3) = 'aaa' ?
« Reply #1 on: July 14, 2021, 10:37:26 am »

Code: Pascal  [Select][+][-]

for spaces specifically

Code: Pascal  [Select][+][-]
1. writestr(result,' ':3);

strutils in general is a mixed string utils units, always worth looking at if you are searching for something

Dupestring is the same but for whole strings, which can also happen to be one char long (and works fine with UTF8!)

https://www.freepascal.org/docs-html/rtl/strutils/dupestring.html

Dseligo below mentioned stringofchar (which I missed): https://www.freepascal.org/docs-html/rtl/system/stringofchar.html
« Last Edit: July 14, 2021, 10:39:50 am by marcov »

#### dseligo

• Sr. Member
• Posts: 344
##### Re: Is there a lazarus function f('a',3) = 'aaa' ?
« Reply #2 on: July 14, 2021, 10:38:30 am »
For string you can use DupeString in StrUtils, for repeating characters you can use StringOfChar.

#### gabriel

• Newbie
• Posts: 4
##### Re: Is there a lazarus function f('a',3) = 'aaa' ?
« Reply #3 on: July 14, 2021, 12:01:40 pm »
Thank you very much.

Dupstring was what I was looking for.

Gabriel