Page 1 of 1

macros for fixed length string from integer, or short string

Posted: Fri Jan 29, 2021 10:29 pm
by eck49
Three simple macros (again just to save typing/typos) to create a string of a fixed length whatever the size or length of the integer/string fed in.
This helps to create a neat and tidy lay out when writing data to a file or in simple printing. The source code does not look as messy, either!
NB There is no check to make sure the fixed length is actually long enough, it is assumed the user knows the range of the input.

Code: Select all

;2021-01-24 new
;macro to deliver integer right-justified in fixed length string
;i is the integer and n the fixed length
Macro UStrX(i, n)
  Right(Space(n) + Str(i), n)
EndMacro

;2021-01-27 new
;macro to deliver string left justified in fixed length string
;st is the string and n the fixed length
Macro UStrLS(st,n)
  Left(st + Space(n), n)
EndMacro

;2021-01-27 new
;macro to deliver string right-justified in fixed length string
;st is the string and n the fixed length
Macro UStrS(st, n)
  Right(Space(n) + st, n)
EndMacro

Re: macros for fixed length string from integer, or short st

Posted: Fri Jan 29, 2021 11:15 pm
by STARGĂ…TE
What is wrong with PB native functions: RSet() and LSet()? Did you miss them?

Re: macros for fixed length string from integer, or short st

Posted: Sun Feb 07, 2021 11:06 pm
by eck49
@STARGATE
I did, but it just shows how hard it is to frame a search. The terms I used did not turn these up at the time.

Re: macros for fixed length string from integer, or short st

Posted: Mon Feb 08, 2021 1:38 am
by Tenaja
You need to hang out in the "library" indexes; in this case:

https://www.purebasic.com/documentation ... index.html