B4J Question Is there a way to return a string repeated X number of times?

Jorge M A

Well-Known Member
Licensed User
I think String lacks the Replicate function. (String.Replicate, String.Repeat, String.Concat...)
It bothers me to do Loops for simple stuff.
Thanks!
 

DonManfred

Expert
Licensed User
1. You need a SHORT small sub to do that. No need to get bothered...
2. you could use the library stringfunctions
https://www.b4x.com/android/help/stringfunctions.html
i guess "PAD" is the method you are searching. Note that stringfunctions is nothing more than a class (or a simple code module) with different subs to do things. all of them are written in B4A.

All of them can be done without a lib (small helper sub as i wrote above).
 

emexes

Well-Known Member
Licensed User
Thank you Don! I'll take option 1, for now.
a/ if doing repetitive string concatenations, use StringBuilder (built-in, no library required, more efficient and quicker than &)
b/ StringFunctions library has function Replicate that seems to do precisely what you originally described
 

Jorge M A

Well-Known Member
Licensed User
StringFunctions
I would not want to use this library, which according to several posts, is out of maintenance, and whose main functions are included in the Core. However, I found a substitute module (StringFunctions2) in case I need anything else.
Thank You.
 

emexes

Well-Known Member
Licensed User
I would not want to use this library, which according to several posts, is out of maintenance, and whose main functions are included in the Core.
Fair enough, no worries :)

If writing your own routine, and at risk of me sounding like a cracked record: use StringBuilder rather than &.
 
Top