Hey Nick
With Python, you can use the function rjust on your string:
txt = "banana"
x = txt.rjust(20, " ")
print(x)
Read more on W3Schools. Python also has a ljust and cjust functions.
MapBasic, on the other hand, has the functions Space$() and String$(). They can achieve the same result but require just a bit more work.
txt = "banana"
x = Space$(20 - Len(txt)) + txt
print x
As you can see above, you need to subtract the current length of the string from the length you are looking for when using the Space$() function, and then concatenate this with your existing string.
String$() is more versatile than Space$() as it can use any string when it builds out the string.
txt = "banana"
x = String$(20 - Len(txt), "-")
print x
Keep in mind, it will only use the first character of the input string if it is longer than 1 character.
I hope this helps
------------------------------
Peter Horsbøll Møller
Principal Presales Consultant | Distinguished Engineer
Precisely | Trust in Data
------------------------------
Original Message:
Sent: 12-09-2025 21:33
From: Nick Lawrence
Subject: MapInfo Monday: String Manipulation with Python
Is there a function to pad a string with whitespace to achieve a string of a specified length?
For example, pad with whitespace on the right so that the string is now 20 characters wide?
------------------------------
Nick Lawrence
Senior Spatial Science Officer
Department of Transport and Main Roads (QLD)
Brisbane QLD
------------------------------