Android Question Printf like funcion for strings

Vinians2006

Active Member
Licensed User
Longtime User
Hi, guys!
I need format a string using a sintax like printf or something equivalent.
In Delphi I used to use Format function like:
B4X:
str = format('%-32.32s | 10.10s |', "Vinicius", "223");

How can I do that in Basic4Android? This is good because is easy to pad strings...
 

LucaMs

Expert
Licensed User
Longtime User
By default, B4A has only NumberFormat, as far as I know (AFAIK? I just learned a new "word")

You can search on the site, there are some string functions (but I do not think they are sufficient for you).

You could develop a nice function with placeholders and then... publish it in the "Snippets" :D
 
Last edited:
Upvote 0

canalrun

Well-Known Member
Licensed User
Longtime User
I'm glad you found that. I've been using this function essentially unmodified since writing it in 2011.

As agraham stated it could be done much more efficiently and is fairly incomplete when compared to the "C" function. I've also learned a lot more about variable type conversions – some of the conversions that I do are simply unnecessary.

But, it has worked for for me, so far. I hope it works for you.

Barry.
 
Upvote 0
Top