Forum > Beginners

Is there a lazarus function f('a',3) = 'aaa' ?

(1/1)

gabriel:
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:
https://www.freepascal.org/docs-html/rtl/strutils/addchar.html
https://www.freepascal.org/docs-html/rtl/strutils/addcharr.html


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---result:=addchar('a',3,'');
for spaces specifically


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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

dseligo:
For string you can use DupeString in StrUtils, for repeating characters you can use StringOfChar.

gabriel:
Thank you very much.

Dupstring was what I was looking for.

Gabriel

Navigation

[0] Message Index

Go to full version