Right Justifying String output

I have created a program to create directories and files and navigate them. The problem im stuck on is that
I'm trying to print the working directory (as a subdirectory) so Im wanting to right justify the current directories name, then call the parent Directory and print its name on the left side of it etc....until I get to root directory.
How do I output the String to the terminal in this fashion ?
Cheers

   public static final int FILL_TO_LEFT = 0;
   public static final int FILL_TO_RIGHT = 1;
   /** Right alignment of string based on the passed width */
   public static String alignRight(String origstr, int width) {
      String retstr = origstr;
      if (retstr == null) retstr = "";
      retstr = retstr.trim();
      if (width > retstr.length()) {
         retstr = fillSpaces(retstr,width,FILL_TO_LEFT);
      else {
         if (width < retstr.length()) {
            retstr = retstr.substring(0,width);
      return retstr;
   /** Fill string with a char based on filling type */
   public static String fillChar(String origstr, int width,
                                 String fillchar, int filltype) {
      String retstr = origstr;
      if (retstr==null) retstr = "";
      retstr = retstr.trim();
      switch(filltype) {
         case FILL_TO_LEFT:  {
                               while (retstr.length()<width) retstr = fillchar + retstr;
                               break;
         case FILL_TO_RIGHT: {
                               while (retstr.length()<width) retstr = retstr + fillchar;
                               break;
      return retstr;
   /** Fill a string with spaces based on passed width and filling type */
   public static String fillSpaces(String origstr, int width, int filltype) {
      return fillChar(origstr, width, " ", filltype);
   }

Similar Messages

  • Right Justify string value in Transformation

    Hi need help
    I have a transform like this.. I need to add 4 spaces before the String "MARKED"
    <ns0:dest>
    <xsl:value-of select='concat(" ","MARKED")'/>
    </ns0:dest>
    but I always get result as
    <dest>MARKED</dest> instead of <dest> MARKED</dest>
    How do I get spaces before string..

    If you add them to the end, they disappear too ?
    can you try adding string() around the " ","MARKED" and second test around the concat().
    don't have a running soa suite installation over here so need to do some guessing

  • Right justify output

    Hi, how do u right justify the output for the below code - not GUI based.
    for (int x=7; x<=10; x++){
    System.out.println(x);
    The output is:
    7
    8
    9
    10
    but i want this format:
    (space)7
    (space)8
    (space)9
    10
    thank you.

    Well, the %d format specifier wants an integer, and you're passing it a string.
    Calling a method as the value passed to printf should not in itself be a problem.
    You probably want to do something more like:
    System.out.printf("%02d    %d%n", x, test());Depending on what test() returns.

  • Tab delimited and Right justified fields

    Hi
    My requirement is to produce an output file where the line items consists of 5 fields of variable lengths and all of them are tab delimited and right justified at the same time
    for eg.
    ABC       123456ghtje  4567.45678   67.45678  pqr
    where all the values in the first field 'ABC' and 2nd field '123456ghtje' are right justified and are tab delimited and asme is the case for '4567.45678' , '67.45678' and 'pqr'
    they are all separated from each other by a tab but are not fixed lengths
    How can i achieve that ? i am using File Receiver Adapter ??
    Can it be done without Adapter Module ?
    Thanks
    Dev
    Edited by: sd on Feb 22, 2010 2:25 PM
    Edited by: sd on Feb 22, 2010 2:26 PM

    > they are all separated from each other by a tab but are not fixed lengths
    When thay are not fixed length fields, why do you have to worry about left or right justification? In delimetted files, you would only have the delimitter between the fields. You do not need to fill spaces for justifying them.
    VJ

  • Lpad .. correct use to right justify a char field?

    Hi all,
    I have a column that's a char type, and I'm trying to manipulate justification within it.
    SQL> create table test (test char(14));
    Table created.
    SQL> insert into test values (' 001234567890');
    1 row created.
    SQL> select * from test;
    TEST
    001234567890
    ..I have no probs making it left justified using ltrim
    SQL> update test set test=ltrim(test);
    1 row updated.
    SQL> select * from test;
    TEST
    001234567890
    ...but when I try to right justify using lpad I can't get it to work:
    SQL> update test set test=lpad(test,14,' ');
    1 row updated.
    SQL> select * from test;
    TEST
    001234567890
    ..this should pad the column with blanks to make the string 14 in length right?
    What am I doing wrong?
    Thanks !
    Adam

    Hi, Adam,
    A CHAR (14) column is always 14 characters long. If you insert a shorter string, it is automatically RPADded.
    If LENGTH (test) = 14, then
    lpad(test,14,' ')
    simply returns test. So your UPDATE statement is equivalent to
    update test set test= test;
    Every row will get UPDATEd, but nothing will get changed.
    To have the strings left-padded, use LPAD before INSERTing, or use UPDATE wtih LPAD and TRIM, like this:
    UPDATE  test
    SET     test = LPAD ( RTRIM (test)
                        , 14
                        );

  • How to do Right Justified in the mappin

    Hi friends,
    Can you help me to do the right justified for example 39.56- this should right side not from left. this field length is 11. infront of this 39.56 should be blank spaceses paded. how to do this
    please help me
    Thanks
    ramidi

    Ramidi,
    Create simple UDF. Let say my input parameter name is "abc" . Write the below code in it
    StringBuffer pad= new StringBuffer();
    String ret_string="";
    int add=0;
    int trunc=0;
    if(abc.length()<=11)
    add =11-abc.length();
    if(abc.length()>11)
    ret_string =abc.substring(0,11);
    else
    for(int i=0;i<add;i++)
    pad.append(" ");
    ret_string = pad.toString()""abc;
    return""ret_string"";
    Hope it helps!!!
    Best regards,
    raj.

  • Pda right justify number WM5.0 and LV PDA 8.0

    Hi :
    I'm trying to Right-justify a number indicator (U32) on my PDA application but I'm having hard time achieveing this ... I have tried what this thread suggests and it doesn't work ... I'm using WM 5.0 and LV 8.0 so that might have something to do with it.  Any suggestions or solutions?  I've thought of converting the display to a string and pad the left side with spaces, but I would rather not do that ... thanks in advance.
    Greycat

    This was reported to R&D (# 3XEBK4G8) and was fixed in LabVIEW 8.2 PDA. Here is a link to the current evaluation software download for LabVIEW.
    Thanks!
    Travis H.
    LabVIEW R&D
    National Instruments

  • Right justify AWT.TextField

    Hey,
    Can anybody tell me how to right justify text in an awt.texfield?
    I know I need to override the paint() method using FontMetrics Class and calculate the new position.
    But how does it work efficiently and how do I need to clear the field and set the Cursor etc.
    (Bonus answer could be, how does it work in comparison to swing/jfc :-), are there already functions to do this?)
    Thanks, Marc
    I tried something like this, but it looks pretty ugly...
    public class TFieldTest extends Frame{
    static TextField t2;
    // do something
    public static void main(String args[]) {
    // create Frame and App here
    TextField t2 = new TextField() {
    public void paint(Graphics g) {
    //super.paint(g);
    Font font = TFieldTest.t2.getFont();
    FontMetrics fm = FieldTest.t2.getFontMetrics(font);
    Dimension size = this.getSize();
    int width = fm.stringWidthTFieldTest.t2.getText());
    g.setFont(font);
    g.drawString(TFieldTest.t2.getText(),size.width-width,fm.getAscent());
    System.out.println("Overwritten Paint in TextField t2 - right justyfied");
    // do more
    }

    Well for purpose, I had 4 textfields that would show the subtotal, taxs, and grandtotal, that had to be aligned right.
    So I use label, and used the Constructor Label(String text, int alignment).
    ex:
    Label lPrix01 = new Label ("", Label.RIGHT);
    lTrans.setBounds(609,387,90,25);
    Then with paint I simply drew lines, to have the effect of a textfield
    g.setColor(white);
    g.drawLine(609,412,699,412);      //hor          Label transport
    g.drawLine(699,387,699,411);      //Ver          Label transport
    g.setColor(noir);
    g.drawLine(609,385,699,385);     //hor          Label transport
    g.drawLine(608,387,608,412);     //Ver          Label transport

  • BEX Query Web-Convert Key Fig to Characteristic-Right justify characteristi

    Hi,
    I have converted a Key Figure into a characteristic. Let's call the new characteristic Z_NUMCHAR.
    When Z_NUMCHAR is displayed in the BEX Query (HTML), it is left justified.
    I have concatenated additional SPACES to the front of Z_NUMCHAR. However when Z_NUMCHAR is displayed, the spaces are removed.
    I have also tried concatenating a letter to the front of Z_NUMCHAR and then a string of spaces, but the spaces are removed. 
    Does anyone have any suggestions on how to right justify a characteristic?
    My worst case solution is to add leading underscores.  _____5482.214
    But would rather see it look like a Key Figure.                           5482.214
    Thanks

    Hi Sebastian,
    I have a similar problem. Can you help me? How did you set the entry in Member Presentation of Command SET_PRESENTATION to display key and text? I just found the values to set the only text or only key.
    best regards,
    Barbara

  • Multiple strings input to single string output

    Dear all,
    this program is needed for my demo simulation purposes, I'm creating several string inputs to show into a single string output updating (input strings are shown in each line). i attached the picture below, put 2 output strings w/c both doesn't meet my desired result:
    1.) 1st string output - replace the old string w/ new string. what i need is to maintain also the previous strings. the new string will go to the next line.
    2.) 2nd string output - although i got all the strings i needed, it only appears right after the while loop terminates, so i did not see the string inputs updating.
    i'm using LV 8.5.1., any help is appreciated... posting your correct code will be more appreciated.
    thanks in advance...
    Ivel R. | CLAD
    Solved!
    Go to Solution.

    here's my code for anyone to see the actual difference.
    thanks,
    Ivel R. | CLAD
    Attachments:
    update strings.vi ‏14 KB

  • Unable To Print Right Justified from Customize Local Layout (Alt+F12)

    Hi,
    Problem I am having is giving me nightmares. I am able to print hebrew text abap list in sap 4.5b. But when i change the Character Set of language from "Customize Local Layout"  (Alt+F12) to Hebrew (Right Justified) the preview shows up correcctly.  But when I print from an actual printer, it still shows output as (Left Justified). Can someone please help!!!!!!

    Hi
    Apologies for replying late. The printer is unicode enabled however, since we are on a non-unicode version of SAP (4.5b) it wouldnt really matter. We are printing Hebrew language. Its always coming out as left justified. We want it to print right justified.
    Awaiting some solution....

  • Unable To Produce RTL (Right To Left) Output in Character Mode Reports

    hi
    Work environment
    - Oracle Forms 6i(client/Server) With pacth 18
    - dot matrix printer
    - Window xp
    Create Report with property "Direction" is "Right to Left"
    NLS_LANG is set to AMERICAN_AMERICA.AR8MSWIN1256.
    While running this report with mode=bitmap, the output columns
    are flipped. The leftmost column appears to the right of the output. This is the expected
    behaviour.
    While running the same report with mode=character and desformat=dflt leftmost column
    remains on the left. The column order is not changed from Right to Left.
    Based on note 332829.1 in metalink
    Should I change dflt.prt file as follows:
    printer "dflt"
    height 66
    width 80
    nls locale "arabic"
    nls datastorageorder
    "logical" nls
    contextuallayout "no"
    nls contextualshaping "yes"
    after page control(L)
    return control(M)
    linefeed control(J)
    i changed, but did not change something
    Where is the problem
    thanks for help

    my Regional and Language settings are:
    standards and formats : Arabic (U.A.E)
    Location : United Arab Emirates
    Language for non-Unicode Programes : Arabic (U.A.E)
    My NLS Settings
    NLS_LANG : ARABIC_UNITED ARAB EMIRATES.AR8MSWIN1256
    USER_NLS_LANG : ARABIC_UNITED ARAB EMIRATES.AR8MSWIN1256
    DEVELOPER_NLS_LANG : AMERICAN_AMERICA.AR8MSWIN1256
    My Report Object Settings:
    Report Direction : Right to left
    all Objects (Frame,Repeating Frame,Fileds..) Setting
    Direction : Right To Left
    Justify : Right To Left
    Note :
    - the Labels frame Direction is ok but Repeating Frame Have Direction Problem
    - Print on Network printer Epson dot matrix
    thanks for all

  • Left- and right-justifying with dot leaders in JLabel and JButton

    Hi,
    I am developing checklists using JLabel and JButton components and want to finish up with the text in each component looking something like the following (each line is a separate button/label):
    ACTION No1............................RESPONSE No1
    ACTION No2............................RESPONSE No2
    ACTION No3............................RESPONSE No3
    The idea is to have the �Action� text left-justified and the �Response� text right-justified with dot-leaders as shown.
    Each text line will be put into its own fixed length label or button.
    I plan to construct a string from text blocks �ACTION No1� and �RESPONSE No1� and add the calculated, exact no of dots in between to fill the space.
    The text font can be fixed (e.g. Courier) or proportional (e.g. Arial).
    My question is how to calculate the number of dots to add to fill the space for different fonts and font sizes.
    I think that using FontMetrics could provide some help but am not sure how this would work.
    Can anyone help.
    Many tks
    John

    Hi,
    I've developed your suggested code further to enable selected JLabels to be toggled visible(true/false) by pressing a JButton.
    I'd like however that when a label is made invisible that the rest of the labels/buttons move up to fill the space left by the now invisible label and vice versa.
    How do I do this, can you enlighten me on a solution?
    Modified code included below. Not very elegant but serves to illustrate the point in question and only makes the label invisible.
    Many tks
    John
    package componentwierd;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ComponentWierd extends JFrame implements ComponentListener, ActionListener {
        boolean isVisible = true;
        JLabel label2 = new JLabel();
        public ComponentWierd() {
            getContentPane().setLayout( new GridLayout(0, 1) );
            // Using my original suggestion
            JLabel label = new JLabel();
            label.setLayout(new BorderLayout());
            label.add(createWierdComponent());
            getContentPane().add(label);
            JButton button = new JButton();
            button.setLayout(new BorderLayout());
            button.add(createWierdComponent());
            button.addActionListener(this);
            getContentPane().add(button);
            // Using Font Metrics
            // JLabel label2 = new JLabel("Label2 West...Label2 East");
            label2.setText("Label2 West...Label2 East");
            label2.addComponentListener( this );
            getContentPane().add(label2);
            JButton button2 = new JButton("Button2 West...Button2 East");
            System.out.println(button2.getIconTextGap());
            button2.addComponentListener( this );
            button2.setVisible(true);
            getContentPane().add(button2);
        public void actionPerformed(ActionEvent e) {
            if (isVisible == true) {
                isVisible = false;
                label2.setVisible(false);
            } else if (isVisible == false) {
                isVisible = true;
                label2.setVisible(true);
        private JComponent createWierdComponent() {
            JPanel panel = new JPanel(new BorderLayout());
            panel.setOpaque( false );
            panel.add(new JLabel("Label WEST"), BorderLayout.WEST);
            panel.add(new JLabel("..............................................."));
            panel.add(new JLabel("Label EAST"), BorderLayout.EAST);
            return panel;
        public void componentResized(ComponentEvent e) {
            if (e.getComponent() instanceof JLabel) {
                JLabel component = (JLabel)e.getComponent();
                String text = component.getText();
                String fitText = fitText(component, text);
                component.setText( fitText );
            if (e.getComponent() instanceof JButton) {
                JButton component = (JButton)e.getComponent();
                String text = component.getText();
                String fitText = fitText(component, text);
                component.setText( fitText );
        private String fitText(JComponent component, String text) {
            // Calculate the total width for painting the text
            // (Not sure why I need the -8)
            Insets insets = component.getInsets();
            int availableWidth = getWidth() - insets.left - insets.right - 8;
            // Calculate the minimum width our text will take
            String start = text.substring(0, text.indexOf("."));
            String middle = "...";
            String end = text.substring(text.lastIndexOf(".") + 1);
            FontMetrics fm = getFontMetrics( component.getFont() );
            int startWidth = fm.stringWidth( start );
            int middleWidth = fm.stringWidth( middle );
            int endWidth = fm.stringWidth( end );
            int minimumWidth = startWidth + middleWidth + endWidth;
            // Add dots to fill out the extra space
            StringBuffer buffer = new StringBuffer(start);
            buffer.append(middle);
            if (minimumWidth < availableWidth) {
                String dot = ".";
                int dotWidth = fm.stringWidth( dot );
                int dots = (availableWidth - minimumWidth) / dotWidth;
                for (int i = 0; i < dots; i++) {
                    buffer.append( dot );
            buffer.append(end);
            String result = buffer.toString();
            return result;
        public void componentHidden(ComponentEvent e) {}
        public void componentMoved(ComponentEvent e) {}
        public void componentShown(ComponentEvent e) {}
        public static void main(String[] args) {
            ComponentWierd frame = new ComponentWierd();
            frame.setDefaultCloseOperation( EXIT_ON_CLOSE );
            frame.setSize(200, 200);
            frame.setLocationRelativeTo( null );
            frame.setVisible(true);
    }

  • Right justify character

    hi All,
    I am having a requirement. client wants to download a record into a .txt file. now the record is AAAASPACEBBBBBDDDD.
    now the problem is DDDD is decimal value and i m converting it to character. however though now the client wants the record such as the field DDDD should be right justfied. now i can right justify if decimal value but since i have converted it to character so that i can use concatenate and write to a file on Pc, i am not able to right justify it.
    can someone give me some suggestions,
    thanks,
    gaurav

    Hi,
    Try with this code.
    Data: v_string type string.
    Data: v_len type i.
    Data: v_int(10) type n.
    Data: v_char(10) type c.
    CONSTANTS c_six(6) type c value '      '.
    v_string = 'Amandeep Sharma1981'.
    v_len = strlen( v_string ).
    v_len = v_len - 4.
    v_int = v_string+v_len(4).
    v_char = v_int.
    v_char+0(6) = c_six.
    Concatenate v_string+0(v_len) v_char into v_string.
    I have taken your numerical value as 4 characters. you can modify as and how you want.
    Regards,
    Aman

  • Right Justify result...

    Hello,
    I have the following query that I am trying to right justify the number results. I've tried to change the number by using "to_char" so that it would automatically justify to the right, however this did not work. here is my query...
    Select to_char(val_11, '9999999.99') where x = y
    Please help if you can.
    Thanks.

    In what way isn't it right justified?
    SQL> select to_char(1234, '999999.99') from dual;
    TO_CHAR(12
       1234.00
    SQL>Formatting of output is dependant on the display environment, not the code producing the data.
    :o/

Maybe you are looking for

  • My iphone 4 doesnt let me download any apps

    im trying to update and put new apps on my phone but everytime i do it says error what should i do? i been having this problem for almost a month and its starting to bother me now because everything i do does not fix it.

  • Transferring from iphone 4s to iphone5

    how to transfer my data and apps to iphone5

  • Appraisals Not Visible to do the appraisal

    Hello All, We have published the PMP, the task is visible from the manager and subordinate login. But when i click the action button in the subsequent form i dont see the manager's subordinates to start the actual appraisal process. Can any one pleas

  • [svn] 1706: Merge svn-1705 to 3.0.x branch

    Revision: 1706 Author: [email protected] Date: 2008-05-14 09:00:31 -0700 (Wed, 14 May 2008) Log Message: Merge svn-1705 to 3.0.x branch 1) Add a security constrain for MBeanObjectNameResolver destination in remoting-config.xml for WebSphere deploymen

  • SSH help

    I've installed WinSCP and OpenSSH Client and OpenSSH Server and can't get it to log in, anyone got any suggestions?