Pad string with leading blanks

Im having trouble with padding leading blanks...
String PRpty_no = "10";
String qsPRpty_no = null;
qsPRpty_no = "PRpty_no=\""+pad(PRpty_no, 5, true)+"\" AND ";
protected String pad(String origString, int requiredSize, boolean justRight){
String theString=origString;
if(justRight){
while(theString.length()<requiredSize){ theString=" "+theString; }
} else {
while(theString.length()<requiredSize){ theString=theString+" "; }
return theString;
Returns:
theString = " 10"
theString = " 10"
theString = " 10"
It only adds 1 blank. The loop is obviously finishing when theString.length=5.
If I replace " " with "0" the desired result comes back:
theString = "010"
theString = "0010"
theString = "00010"
What is the difference using " " to "0"?

Unfortunately not GreyMan, copyright and all that. In the end the strings get concatenated into an sql query then run:
String sql="SELECT PRupi FROM PRprop WHERE ("+qsPRpty_no+qsPRpty_suffix+qsPRroad_id+")";
Where PRpty gets pulled out from an earlier sql as "10" and qsPRpty needs to be " 10" not " 10".

Similar Messages

  • Fieldcontent in field catalog in ALV GRID with leading blanks to be display

    Hello,
    I want to display the result of a report in an ALV Grid.
    There are different columns in the ALV, one of them contains text, sometimes with leading blanks.
    The ALV does not display the blanks, cut them and moves the rest to the left.
    I have used LVC_S_FCAT-JUST with 'R' but this moves the content of the field only to the right (right justified), so that it looks like there is always a lot of blnks on the left side . 
    Is there any possibility to display blanks when they appear in the text field?
    e.g.
    TEXT1 (10)
      9991-A
    9950-B
          9090-T
    9675-N
    Do´t ask, why there are leading blanks. It is always your customer or manager who determines the results!
    Thank you very much for any hint that brings happiness into the face of  this customer / manager.
    Best regards
    Dirk

    Hi Sunil,
    unfortunately this did not help!
    But what can I expect, when the forum works the same.
    e.g.
    TEXT1 (10)
    9991-A
    9950-B
    9090-T
    9675-N
    should more look like:
    e.g.
    TEXT1 (10)
    9991-A
    _9950-B
    ___9090-T
    __9675-N
    but without all the '_'.  
    Regards
    Dirk

  • Padding String with spaces -tried known methods but code not working!

    I am trying to figure out an easy way to pad a string with spaces at the end. The way that definitely works is a for loop where string = string + " "; until string is the length that I need. However, for several dozen strings this is a lot of unnecessary overhead. I've done some research and tried a few different things - yet none of them seem to actually pad the string.
    import org.apache.commons.lang.StringUtils;
    public class Test
         public static void main(String[] args)
              String one = "1234";
                    //print string at current lenght
              System.out.println(one+"*");
                    //try padding using String.format (in padRight method below)
              one = padRight(one,(8-one.length()));
              System.out.println(one+"*");
                    one="1234";
                    //try padding using StringUtils
              String tmp = StringUtils.rightPad(one, (8-one.length()));
              System.out.println(tmp+"*");
         private static String padRight(String s, int n)
              return String.format("%1$-" + n + "s", s);
    }I've researched and these are the two most common methods people are suggesting. I am using java 1.5 so the String.format should work.. however, when I run it (I use JBuilder) the output is always "1234*".... after I try to pad it the output should be "1234 *" (with 4 spaces between the 4 and *) . Any suggestions is greatly appreciated! Thanks in advance.

    Wow, I completely botched that... uncle_alice, thank you for clearing that up for me.
    pbrockway2 - thank you, I actually did peruse the Formatter documentation - I would never post without researching something first... but I must have read it with one eye shut because walked away with the impression that I needed to submit the difference. I obviously misunderstood the documentation.
    Thanks!

  • Multi-value parameters and strings with leading zeros

    I have invoice number as a multi-value parameter. Invoice is a string,10 (VBRP.VBELN) .
    Invoice number is my group. If I enter invoices 100 and 200 as parms, then I only get data for invoice #100 (the lowest value entered). But if I enter 100, 0000000100, 200, 0000000200 as parms, then I get data for both invoices. Is there a way to get around having to enter the invoice number in both formats. BTW, if I only enter 0000000100 and 0000000200 then I get no data.
    Selection criteria is (VBRP.VBELN) = ?invoiceno --- parms are defined as allow muliple values and allow discrete values.

    Oops, that's not gonna work with multi-value parameters.  How about:
    if IsNumeric((VBRP.VBELN)) then
      ToText(Val((VBRP.VBELN)), "0") in {?invoiceno}
    else
      (VBRP.VBELN) in {?invoiceno}
    end if
    BTW, the reason why your original formula didn't work was because the "=" should have been "in".  The above is needed only if the (VBRP.VBELN) field might contain leading zeroes.
    HTH,
    Carl

  • Sequence with leading zeros

    Hi,
    I have a column SRL_NUM with datatype varchar2(4 char).I have 3000 records in this table and want to make SRL_NUM like 0001,0002,0003 etc.It should increment but entire 4 characters should be filled.How do i do this?
    Thanks.

    user10698496 wrote:
    I have a column SRL_NUM with datatype varchar2(4 char).I have 3000 records in this table and want to make SRL_NUM like 0001,0002,0003 etc.It should increment but entire 4 characters should be filled.How do i do this?Why is the sequence a varchar2 and not a number?
    IMO it makes more sense to use a native number data type as that is what a sequence generator outputs - and then render that as a text string with leading zero as "+how it looks like+" is a presentation layer issue.
    I would not use a numeric sequence generator to generate unique strings as surrogate key values. There are inherent problems with mixing data types like that.

  • OpenSQLException caught: Cannot assign a blank-padded string

    Hi,
    sometimes I get this exception, when updating a bo instance.
    I didn't managed it to reproduce the error, because it is thrown in a complex background job.
    Can anybody give me more information about the reason behind this?
    Thanks,
    Jens
    stacktrace:
    com.sap.sql.log.OpenSQLException: Cannot assign a blank-padded string to host variable 13.
    at com.sap.sql.log.Syslog.createAndLogOpenSQLException(Syslog.java:95)
    at com.sap.sql.log.Syslog.createAndLogOpenSQLException(Syslog.java:188)
    at com.sap.sql.jdbc.common.dispatch.VarcharHostVariable.setString(VarcharHostVariable.java:34)
    at com.sap.sql.jdbc.common.CommonPreparedStatement.setString(CommonPreparedStatement.java:626)
    at com.sap.engine.services.dbpool.wrappers.PreparedStatementWrapper.setString(PreparedStatementWrapper.java:380)
    at com.sap.engine.services.orpersistence.jdbcaccess.StringBinder.setValue(StringBinder.java:33)
    at com.sap.engine.services.orpersistence.core.StoreManager.bindParameterValues(StoreManager.java:387)
    at com.sap.engine.services.orpersistence.core.StoreManager.executeStatement(StoreManager.java:652)
    at com.sap.engine.services.orpersistence.core.StoreManager.updateEntity(StoreManager.java:625)
    at com.sap.engine.services.orpersistence.core.PersistenceContextImpl.flush(PersistenceContextImpl.java:300)
    at com.sap.engine.services.orpersistence.entitymanager.EntityManagerImpl.flush(EntityManagerImpl.java:121)
    at com.sap.engine.services.orpersistence.entitymanager.EntityManagerHandleImpl.flush(EntityManagerHandleImpl.java:50)
    at com.sap.engine.services.orpersistence.container.EntityManagerProxy.flush(EntityManagerProxy.java:105)
    at com.sap.caf.rt.bol.da.jpa.JPADataAccessService.store(JPADataAccessService.java:495)
    at com.sap.caf.rt.bol.da.jpa.JPADataAccessService.store(JPADataAccessService.java:483)
    at com.siemens.sm3k.mntstrat.modeled.bonode.functionfailure.functionfailure.FunctionFailureBean.update(FunctionFailureBean.java:137)

    Hi,
    I got the same exception with the following code:
    stringVarible="someString"+someMethod.getValue();
    here getValue returns String.But sometimes it may return null valu also.when it returns null value,the same SQL Exception will occure becuse we are trying to save a string in SQL which is blank padded.
    I think your code is also having the similar problem.
    Sampath

  • Padding a julian date with leading zeros ?

    Hi,
    I have gernerated a julian date, which I am appending to another two digit number to create a five digit serial number.
    Is there a simple way to pad the first 99 days with leading zeros ( i.e. 001, 002....025...099) so that I maintain a five digit serial number ?
    I am using   Get Date In Time/Seconds > Number To Decimal String > Unbundle >Number to Decimal String.
    Thank you in advance for any advice,
    Alan

    Here's the simplest way to do it (with he 2 digit number), I believe:
    Message Edited by Matthew Kelton on 02-21-2008 12:43 AM
    Attachments:
    Julian1.png ‏3 KB
    Julian2.png ‏2 KB

  • Padding a value with leading zeros

    Hi
    I am trying to create a filename (String) using a sequence int. I need this int to be 6 digits, with leading zeros
    i.e. if my seqence number is 23 my filename (String) should be:
    FILE000023
    Obviously I can do this by creating my own method that iterates through the number, but I was wondering if there was a simple method to change an int to a String and pad it out with leading zeros.
    Thanks
    Neil.

    import java.text.*;
    public class DecimalFormatTesting {
         public static void main( String[] args ) {
              DecimalFormat format = new DecimalFormat("###.###");
              format.setMinimumIntegerDigits( 6 );
              String integ = format.format( 123 );
              System.out.println("str: " + integ);
         } // end of main()
    }hope this helps
    partha

  • How to replace a character in a string with blank space.

    Hi,
    How to replace a character in a string with blank space.
    Note:
    I have to change string  CL_DS_1===========CM01 to CL_DS_1               CM01.
    i.e) I have to replace '=' with ' '.
    I have already tried with <b>REPLACE ALL OCCURRENCES OF '=' IN temp_fill_string WITH ' '</b>
    Its not working.

    Hi,
    Try with this..
    call method textedit- >replace_all
      exporting
        case_sensitive_mode = case_sensitive_mode
        replace_string = replace_string
        search_string = search_string
        whole_word_mode = whole_word_mode
      changing
        counter = counter
      exceptions
        error_cntl_call_method = 1
        invalid_parameter = 2.
    <b>Parameters</b>      <b> Description</b>    <b> Possible values</b>
    case_sensitive_mode    Upper-/lowercase       false Do not observe (default value)
                                                                       true  Observe
    replace_string                Text to replace the 
                                         occurrences of
                                         SEARCH_STRING
    search_string                 Text to be replaced
    whole_word_mode          Only replace whole words   false Find whole words and                                                                               
    parts of words (default                                                                               
    value)
                                                                               true  Only find whole words
    counter                         Return value specifying how
                                        many times the search string
                                        was replaced
    Regards,
      Jayaram...

  • Scan String Token Problem with leading Tokens

    Hi, I'm using the scan string for token to read in a string of tokens that contain a leading "*" char in front of each string and terminates when the token index = -2. This works great if I have say *12345*1234 and so forth, but if there is bad data, say 1234 without the leading "*" in front, the token index return value is still -1 and it returns data which I read in thinking it found the "*". Maybe I shouldn't use the string for token function since it's probably just designed for ending tokens and not data with leading tokens. Is there a way to make this work properly or should I use another method to search for leading tokens in a string?
    Thanks.
    Solved!
    Go to Solution.

    Here.  Try this one.  It does the same thing and uses exposed functions.
    The string functions look for something to mark the end of a string.  All languages that I know of do this.  So, like I said, remove the first element.  I recommend the Subarray function with the index set to 1 and length unwired.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Parse Message.png ‏10 KB

  • Pad a string with zeros ?

    Hello ABAP Experts,
    How to pad a string with zeros.. is there a direct method i can use.
    eg:
    string length is 8
    string is custnumb
    value is 588
    but i would like to see 00000588
    please suggest.

    You can simply move it to a TYPE n field also.
    data: n(8) type n.
    data: custnumb(8) type c value '588'.
    n = custnumb.
    custnumb = n.
    Regards,
    Rich Heilman

  • Concatenating numbers with leading zeros into a global string in DasyLab

    I need to format a global variable into a global string with the field width exactly three characters long. For example, if the global variable is 1, the global string needs to be "001". I tried using strfmt(${VAR_801},3,0) as the expression under the extended global string dialog, but that results in "1". Any help or suggestions are appreciated.

    Hello Mark,
    DasyLab support is handled through the following website.
    DASYLab
    www.dasylab.net
    Regards,
    Todd D.
    NI Applications Engineer

  • How to pad a string with space or other character

    length 14 string '00000000000155' turn to length 25 string '00000000000155         ' ,use space to pad string trail.
    using following function:
    CONCATENATE '00000000000155' '         ' into lv_string
    but result is the lv_string ='00000000000155',the spaces were not added the string trail.
    how to achieve this purpose padding string.
    pls help me.
    thank you.

    Hi ,
    Not sure what exactly you require, But in my understanding you need to add one more spave after the doknr no. Please refer this code which could be more useful.
    data: lv_objkt like aeoi-OBJKT,
          lv_doknr like draw-doknr,
          lv_dokar like draw-dokar,
          lv_doktl like draw-doktl,
          lv_dokvr like draw-dokvr,
          lv_slen type i.
    lv_dokar = 'DRW'.
    lv_doknr = '00000000000155'.
    lv_doktl = '000'.
    lv_dokvr = '-'.
    CONCATENATE lv_dokar lv_doknr INTO lv_objkt.
    lv_slen = STRLEN( lv_objkt ).
    lv_slen = lv_slen + 1.
    lv_objkt+lv_slen(3) = lv_doktl.
    CONCATENATE lv_objkt lv_dokvr INTO lv_objkt.
    WRITE: lv_objkt.

  • Removing leading zeros and leading blank spaces from an input field

    Hi All,
    I have an input field which is alphanumeric and i need to remove the leading zeros and blank spaces in it , but intermediate spaces should be kept .
    so i used the UDF
            String output = input.replaceFirst("^0+","");
            return output;
    but this code does not remove the leading blank spaces . Can anybody help in modifying this code so that even the leading blank spaces along with leading zeros  can be removed .
    Regards ,
    Loveena .

    lets say input is a
    then
    int len = a.length();
    for(int i;i< length;i++)
    if(a.substring(0,1).equals(" ") || a.substring(0,1).equals("0"))
    a = a.substring(1,len);
    return a;
    hope you got the logic so that you can enhance it better

  • Display numbers formatted with leading zeros or spaces.

    There are some cases where you might need to display numbers with leading zeros or leading spaces, or trailing zeros.  I experimented with several methods and came up with some examples.  This is a Console application, but the results can just
    as well be output to a listbox in a Windows form.
    Sub Main()
    Dim snum As String, inum As Integer = 56
    snum = inum.ToString()
    Console.WriteLine(snum & vbTab & " ToString()")
    snum = inum.ToString("D4") 'adds leading zeros
    Console.WriteLine(snum & vbTab & " ToString(""D4"")")
    snum = inum.ToString("F4") '4 decimal places with trailing zeros
    Console.WriteLine(snum & vbTab & " ToString(""F4"")")
    Console.WriteLine()
    snum = String.Format("{0,4}", inum) 'leading spaces
    Console.WriteLine(snum & vbTab & " Format{0,4}")
    snum = String.Format("{0:D4}", inum) 'leading zeros
    Console.WriteLine(snum & vbTab & " Format{0:D4}")
    snum = String.Format("{0:F4}", inum) '4 decimal places with trailing zeros
    Console.WriteLine(snum & vbTab & " Format{0:F4}")
    Console.WriteLine()
    snum = inum.ToString().PadLeft(4, "0"c) 'leading zeros
    Console.WriteLine(snum & vbTab & " PadLeft(4, ""0""c)")
    snum = inum.ToString().PadLeft(4, " "c) 'leading spaces
    Console.WriteLine(snum & vbTab & " PadLeft(4, "" ""c)")
    Console.ReadLine() Console.Clear()
            For x As Integer = 1 To 20
                snum = x.ToString("D4")
                Console.WriteLine(snum)
            Next x
            Console.ReadLine()
    End Sub
    Solitaire

    I would add that many of these methods also work with numeric types that are not integers.
    Note that the "D4" format string doesn't work for non-integral types (such as Double and Decimal), and the "F4" format string doesn't pad with trailing zeros, it rounds to 4 decimal places (which can lose information). PadLeft works with
    the entire string, it isn't aware of the decimal point.

Maybe you are looking for

  • My computer has died and I have bought a new one. I need to get my book marks back

    I have a laptop that has been synced with the computer that is now dead and it has 90% of the Bookmarks that I want. I have tried to sync between the laptop & the computer but nothing is working.

  • Order by disk sort porblem

    hi friends i have a querry which return 40.000 rows and 2 mb data. this querry works in 1-2 seconds. if i add simple order by to querry it work in 20 seconds. i think because of disk sort. but i have another querry which have 270.000 row and 8 mb dat

  • Zip file download

    Hi, I want perform two tasks. One is displaying the page content and then to prompt the user tow save /download the zip file. I used the below code. <script> window.open("/path/software.zip",1,1); </script> Sequence of flow is, once the user submits

  • Color question

    Running Photoshop CS3 intel mac leopard. I made a .psd file with spot PMS 307 chosen from the PMS picker, not as a separate channel. I made another file at home on a imac running 10.4.11 CS2 with PMS 307 chosen the same way. Both are RGB files, both

  • Eps files 20 minutes for saving

    I've bought a new Windows Workstation in order to use my Adobe Illustrator CC. All works fine, i've only this sad problem, my eps files that I worked with my old Windows Workstation (WindowsXP) are very very slow in saving, about 20 min, the program