Extension of the IJ.pad method

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Extension of the IJ.pad method

CARL Philippe (LBP)
Dear all,
Would it be of common interest to have a IJ.pad(n, length, str) method which would able to pad whatever string (i.e. not only zeros)?
Actually in my application, I would need to pad spaces (i.e. having str = " ").
I thank you very much for your lighting on this.
My best regards,
Philippe


Philippe CARL
Laboratoire de Bioimagerie et Pathologies
UMR 7021 CNRS - Université de Strasbourg
Faculté de Pharmacie
74 route du Rhin
67401 ILLKIRCH
Tel : +33(0)3 68 85 42 89

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Extension of the IJ.pad method

Gabriel Landini
Hi, would this help?:
https://stackoverflow.com/questions/388461/how-can-i-pad-a-string-in-java
You use String.format() and then the replace method.

Cheers

Gabriel

On Friday, 12 June 2020 11:43:17 BST [hidden email] wrote:
> Dear all,
> Would it be of common interest to have a IJ.pad(n, length, str) method which
> would able to pad whatever string (i.e. not only zeros)? Actually in my
> application, I would need to pad spaces (i.e. having str = " "). I thank
> you very much for your lighting on this.
> My best regards,
> Philippe

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Extension of the IJ.pad method

CARL Philippe (LBP)
Dear Gabriel,
Actually I needed this (these) code(s) in macro and have already solved my needs by the following small macros:
        function padStart(str, digits, ins) {
                while (lengthOf(str) <digits)
                        str = ins + str;
                return str;
        }

        function padEnd(str, digits, ins) {
                while (lengthOf(str) <digits)
                        str = str + ins;
                return str;
        }
for which I inspired from the pad method code found in the ij.IJ.java file.
I was just asking whether there could be a need for further extension of the existing method since I may not be the only one needed this.
Take care,
Philippe

----- Mail original -----
De: "Gabriel Landini" <[hidden email]>
À: "imagej" <[hidden email]>
Envoyé: Vendredi 12 Juin 2020 13:06:35
Objet: Re: Extension of the IJ.pad method

Hi, would this help?:
https://stackoverflow.com/questions/388461/how-can-i-pad-a-string-in-java
You use String.format() and then the replace method.

Cheers

Gabriel

On Friday, 12 June 2020 11:43:17 BST [hidden email] wrote:
> Dear all,
> Would it be of common interest to have a IJ.pad(n, length, str) method which
> would able to pad whatever string (i.e. not only zeros)? Actually in my
> application, I would need to pad spaces (i.e. having str = " "). I thank
> you very much for your lighting on this.
> My best regards,
> Philippe

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html