How to get a string with fixed length

I want to implement something like movechar() of c in java. I want to return a string which has a fixed length that contains the given string and spaces for remaining length.
Please let me know how can I implement it.
Thanks & Regards,
Nasrin.n

Do you mean padding a String?
      * This method pads the string s to size n using char c to make up for missing characters.
     public static String padString(String s, int n, char c, boolean paddingLeft) {
          StringBuffer str = new StringBuffer(s);
          int strLength = str.length();
          if (n > 0 && n > strLength) {
               for (int i = 0; i <= n; i++) {
                    if (paddingLeft) {
                         if (i < n - strLength) str.insert(0, c);
                    else {
                         if (i > strLength) str.append(c);
          return str.toString();
     }

Similar Messages

  • How to get the string's byte length?

    I have some string,I want to get the string's byte length,how
    can do it?
    for example:
    <cfoutput>#len('hihi,这是测试')#</cfoutput>
    output is 9
    I want to get the byte length is 14, how can i get it?
    Thanks.

    >> Fair cop. I didn't realise that asc() returned the
    codepoint rather than the
    > actual character code.
    >
    > and what would be the difference?
    Oh, sorry, whatever the term is (I'm crap with jargon). The
    value returned
    by asc() for those chars was only two bytes (ie: four hex
    digits). I
    didn't realise there was more to it than that, and that
    2-byte value maps
    to some other THREE byte value. I need to do some reading...
    > that's what both cf & java counted as the length.
    CHARACTER length, sure. No-one's disputing that. On the other
    hand,
    no-one's asking about it, either.
    > by adding a BOM you've already effected the encoding,
    which may or may not
    > match the original. so you still don't know how many
    bytes were in the original
    > string.
    [groan]
    Yes, that's a reasonable strawman there. I was only putting
    it in a file
    so I could save it and check the number of bytes occupied by
    the data.
    Clearly... CLEARLY... the OP is not asking for a character
    length of that
    string. They've said as much.
    I copy and pasted the string from their post, and used it as
    a
    demonstration of how "nine" is not the right answer for the
    BYTE LENGTH of
    that string. Whether or not the original string was UTF-8,
    UTF-16 or
    special-marmoset-encoding, it almost certainly was NOT in a
    fictitious kind
    encoding in which each of those particular characters only
    occupied one
    byte each, which would mean that "nine" is the correct answer
    to the
    question.
    When I copied those characters from either the web browser
    for from my
    text-based news agent, notepad identified them (and rendered
    them
    correctly) as UTF-8, so I'm fairly confident they ARE UTF-8.
    Of course
    this could be down to some intermediary encoding (pasting
    them in to the
    original posting, for example, via some encoding-transforming
    mechanism),
    but Occam's Razor suggests the original question was from a
    UTF-8 POV.
    But maybe we should quit speculating and ask the OP. Unless
    they've
    buggered off in despair of how drawn out all this is getting.
    For which I
    would not blame them.
    Adam

  • How to get input  string with resolved '?' of PreparedStatement?

    Is there a way to retrieve the input string of a PreparedStatement?
    Example:
    ps = connection.prepareStatement("update t1 set name=?");
    ps.setString(1, "test");Now, can I get the input string "update t1 set name=?" back from the PreparedStatement object with the '?' resolved? In this case:
    update t1 set name='test'
    ?

    Sir,
    Thank you first for responding. I appreciate your time in dicussing things here. Just saying.
    I see that you suggested and that is sort of agood
    tool for this but I think I would want to do more
    testing with the actual driver no?
    Not sure what you mean by "testing with the actual
    driver". The suggestion that I made is a proxy, not
    a substitute.
    Right. Never mind. I got myself confused.
    Actually I would like to ask a serious question
    here... can you give an example of why you don'tknow
    what the SQL will look like? I'm just trying to
    understand why you don't know and I'm strugglingwith
    that.1. Dynamic creation of SQLUgh. Okay. But still ugh.
    2. Unknown input of parameters.I still don't understand why they would be unknown if it is your app inputting them.
    Sincerely,
    Slappy

  • How to map xml to a fixed length string?

    Hi All,
    I have a requirement to map request xml to a string of fixed length and format:
    For eg,
    Source:
    <Person>
    <Name>George</Name>
    <Age>21</Age>
    </Person>
    Target:
    String of format
    Name : 8 chars
    Age : 2chars.
    so the required mapping should result in
    "George 21".
    Note: 2 blanks after "George" to allow for 8 characters. Is this kind of mapping possible using ALSB xquery? I have tried to create a MFL representation for the string , and used it in the xquery as the targer but it is generating
    "George21".Only data present in source is getting mapped :(

    My advice would be to use MFL transformation for that.
    Documentation about MFL can be found at edocs: http://edocs.bea.com/alsb/docs26/fbhelp/index.html
    Find tips and tricks about ALSB at my blog: http://dev2dev.bea.com/blog/jordinho/

  • Send a flat file with fixed lengths to XI 3.0 using a Central File Adapter?

    Hello,
    I'm wondering if someone have experience setting up conversion for different record structures. The example shown,
    /people/michal.krawczyk2/blog/2004/12/15/how-to-send-a-flat-file-with-fixed-lengths-to-xi-30-using-a-central-file-adapter,
    (in a greate way) only picture one kind of structure.
    How should it be done if the file would contain
    10Mat1
    20100PCS
    The first record structure has columns
    ID(2),Material(10)
    The second redcord structure has columns
    ID(2),Quantity(3), Unit of messure (3)
    Brgds
    Kalle
    Message was edited by: Karl Bergstrom

    The configuration would be like follows:
    Content Conversion Parameters:
    Document Name: <your message type name>
    Document Namespace: <your message type namespace>
    Document Offset: <leave empty>
    Recordset Name: <any name>
    Recordset Namespace: <leave empty>
    Recordset Structure: row1,,row2,
    Recordset Sequence: any
    Recordsets per Message: *
    Key Field Name: ID
    Key Field Type: String
    Parameters for Recordset Structures:
    row1.fieldNames           ID,Material
    row1.fieldFixedLengths    2,10
    row1.keyFieldValue        10
    row2.fieldNames           ID,Quantity,UOM
    row2.fieldFixedLengths    2,3,3
    row2.keyFieldValue        20
    Instead of row1 and row2 you can choose any name.
    Regards
    Stefan

  • Flat file with fixed lengths to XI 3.0 using a Central File Adapter---Error

    Hi
    According to the following link
    /people/michal.krawczyk2/blog/2004/12/15/how-to-send-a-flat-file-with-fixed-lengths-to-xi-30-using-a-central-file-adapter
    In Adapter Monitor I got the following error,
    In sender Adapter,
    Last message processing started 23:47:35 2008-10-25, Error: Conversion of complete file content to XML format failed around position 0 with java.lang.Exception: ERROR converting document line no. 1 according to structure 'Substr':java.lang.Exception: Consistency error: field(s) missing - specify 'lastFieldsOptional' parameter to allow this
      last retry interval started 23:47:35 2008-10-25
      length 15,000 secs
    some one help me out ?
    Thanks
    Ram

    from the blog you referenced -
    <u> /people/michal.krawczyk2/blog/2004/12/15/how-to-send-a-flat-file-with-fixed-lengths-to-xi-30-using-a-central-file-adapter
    <b>goto step 4</b>
    <u>additional parameters</u>
    add as the last entry
    <recordset structure>.lastFieldsOptional            Yes
    e.g.,
      Substr.lastFieldsOptional            Yes

  • How to get command history with timestamp ?

    how to get command history with timestamp ?

    If you are using bash:
    HISTTIMEFORMAT If this variable is set and not null, its value is used as a format string for strftime(3) to print the time stamp associated with each history entry displayed by the history builtin. If this variable is set, time stamps are written to the history file so they may be preserved across shell sessions.
    [SunOS 5.10/bash] [email protected]:/etc/ftpd
    # HISTTIMEFORMAT="%h/%m - %H:%M:%S ";export HISTTIMEFORMAT;history
        1  Aug/08 - 19:07:52 chmod a+rwx /root
        2  Aug/08 - 19:07:52 ll /
        3  Aug/08 - 19:07:52 tail -f /root/mylog.log
        4  Aug/08 - 19:07:52 vi /usr/dt/bin/Xsession
        5  Aug/08 - 19:07:52 cat /root/mylog.log
        6  Aug/08 - 19:07:52 ls /export/home/p661210/.dt
        7  Aug/08 - 19:07:52 ls -la  /export/home/p661210/.dt
        8  Aug/08 - 19:07:52 cat  /export/home/p661210/.dt/errorlog
        9  Aug/08 - 19:07:52 vi /usr/dt/config/C/sys.dtwmrc
       10  Aug/08 - 19:07:52 ls
       11  Aug/08 - 19:07:52 cat Xresources.jds
       12  Aug/08 - 19:07:52 vi /usr/dt
    [SunOS 5.10/bash] [email protected]:/etc/ftpd
    [SunOS 5.8/bash] root@wgls03:/root
    # HISTTIMEFORMAT="%h/%m - %H:%M:%S ";export HISTTIMEFORMAT;history
        1  Jul/07 - 09:02:21 vi /etc/vfstab
        2  Jul/07 - 09:02:21 mount /store
        3  Jul/07 - 09:02:21 cd /store/bnz
        4  Jul/07 - 09:02:21 ls
        5  Jul/07 - 09:02:21 ./BNZ_installBaseSoftware
        6  Jul/07 - 09:02:21 find /usr -name gunzipCheers,
    Andreas

  • How to get alternative strings in list of strings.

    Hi experts,
    how to get alternative strings in list of strings.
    eg
    'country1, italy, country2, india, country3, paris, country4, scottland, country5, rome'
    from the above list i need to fetch all the countries and their names separately.
    like country1, country2, country3, country4, country5
    italy, india, paris, scottland, rome
    i am trying the above one in the below fashion
    SELECT SUBSTR
              ('country1, italy, country2, india, country3, paris, country4, scottland, country5, rome',
               1,
                 INSTR
                    ('country1, italy, country2, india, country3, paris, country4, scottland, country5, rome',
                     1,
                     1
               - 1
      FROM DUAL
    can you please any one help me

    If you want the data to be more stuctured, and useful:
    col col_name for a20
    col col_value for a20
    var inlist VARCHAR2(2000)
    exec :inlist := 'country1, italy, country2, india, country3, paris, country4, scottland, country5, rome';
    exec :inlist := replace(:inlist,' ')
    select max(decode(mod(lvl,2),1,value)) col_name
          ,max(decode(mod(lvl,2),0,value)) col_value
    from   (select substr(:InList,start_pos+1, end_pos-start_pos-1) value
                  ,lvl
            from   (select :InList
                          ,case when level = 1 then
                             0
                           else
                             instr(:InList,',',1,level-1)
                           end start_pos
                           ,case when instr(:InList,',',1,level) = 0
                             then length(:InList)+1
                           else
                             instr(:InList,',',1,level)
                           end   end_pos
                         ,level lvl
                    from   dual
                    connect by level <=length(:InList)-length(replace(:InList,','))+1
    group by ceil(lvl/2)
    order by 1;
    COL_NAME             COL_VALUE
    country1             italy
    country2             india
    country3             paris
    country4             scottland
    country5             rome
    Untested on 10g
    Then you could stragg the rows together ...

  • How to get spool along with e-mail or FAX

    Hi,
    I have a requirement where i have to produce a spool even i go for e-mail or FAX option when the script is triggered.
    I am using a standard program where it is coded to have either of the option. i.e. either we have to go for a printer or e-mail or FAX.
    Could any one suggest me how to get spool along with e-mail or FAX option.
    Thanks in advance.

    Hi,
    check this:-[http://help.sap.com/saphelp_nw04/helpdata/en/a5/28d3b9d26211d4b646006094192fe3/frameset.htm]
    hope u'll get some idea.
    Regards,
    Sneha.

  • I have a problem with mail.  the spelling and grammer check box before sending the messege is no longer there.  I did everything but cannot get it back.  is ther anyone who knows how to get the box with spelling and grammer checks before sending

    i have a problem with mail.  the spelling and grammer check box before sending the messege is no longer there.  I did everything but cannot get it back.  is ther anyone who knows how to get the box with spelling and grammer checks before sending the mail.
    Also the mail is acting very funny by not getting the rules work in a proper method.  Is ther a software to repair mail.

    i did both of them, but still the while sending the mail the diolog box is not showing up and also the spelling and grammer does not do the spelling check. 
    This problem just started for about 3 to 4 days now.  earlier it was working normally.

  • How to Create Business Partner with  fix number in t-code :BP

    Dear SIr,
    Normally I will set number range for auto  to create Business Partner. In case , If we would like to crea How to Create Business Partner with  fix number in t-code :BP , howe to do?
    Please kindly advise.
    THnak you and best regards,
    Vimol

    Dear Shobhit,
    How to put the thread as you mentioned.
    Best regards,

  • Is it possible to display a waveform with fixed length and fixed starting point?

    Hi,
    I am using DAQ assitant to acquire voltage and current measurment of my device. The voltage is a pure sine wave and current is a periodic waveform with phase difference and distortion. I use waveform chart to display the waveform of voltage and current waveform in seperate charts and they work fine.But the waveforms look like moving to the right all the time, in another way ,the phase is always shifting. Now i want to display the waveforms of both with fixed length (say 2 cycle) and also in a same chart. Apart from that, i also want to display the voltage waveform starting form 0 degree (a fixed point )rather than moving all the time. In this case, i can observe the angle difference between voltage and current. Is there any method to achieve this purpose?
    Many Thanks,
    Hao

    Hao,
    first of all, you are using a chart which has three options for updates if the chart is "full":
    Strip chart (default)
    Scope chart
    Sweep chart
    These are called "update mode". Test the modes yourself.
    Also you have to know that you will not likely have an integer number of periods of your signal in the display of the chart. Therefore, a continuous signal will "move" the graph from update to update.
    You can implement some algorithm to discard data to maintain a static "trigger" level for display, but as stated, it will leave gaps in the signal. These gaps are not a concern unless you use the displayed signal for analysis (e.g. FFT).
    Norbert
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • How to create a String with a specific size?

    how to create a String with a specific size?
    For example I want to create different Strings with the size of 100 , 1000 or 63k byte?

    String are immutable so just initialize it with the number of characters you want.
    You might want to look at java.lang.StringBuffer and see if that's what you want.

  • How to concatenate a string with single quotes

    Hi all,
        how to concatenate a string with single quotes to a variable.
    Sathya

    Hi sathyabama,
    1. simple
    2. use TILDE character <b>(`)</b>
       (just left to the '1' key)
    <b> `'mystring'`</b>
    3. just copy paste
    report abc.
    data : m(100) type c.
    concatenate `'amit mittal'` 'hello' into m separated  by space.
    write m.
    regards,
    amit m.

  • How to print a string with out using main method??

    how to print a string with out using main method??
    if we can tell me with example?
    thanks in adavance
    raja

    Hi,
    actually there's none. The UITableView class needs to "know" the tableView's height so either it can calc <number of rows> times <row height> or it has to sum the height of each single row.
    If the row which needs to be of different size always is the first or the last row you can user a tableHeader or tableFoot view.
    Regards
    Dirk

Maybe you are looking for

  • AE CS6:  Could not convert Unicode characters (23 :: 46)

    I am sudenlty getting this error message. I was importing a native XDCAM file into AE Win 7 when the error message first appeared.  Subsequent to that, merely clicking on the import button (no file selected) gives the same error message. It seemed to

  • Power Mac G4 won't boot in OS X

    I have a number of G4's which have been upgraded to Tiger. I am on the last machine running 9.2.2 and it refuses to boot in 10.4. I have tried the Tiger installation CDs, from a firewire drive with a good copy of Tiger on and from a new internal disk

  • Problem uploading wmv video

    I am trying to upload a 38MB video to a site. When I hit "put", the icon shows DW disconnecting from the host. It then proceeds to up load normally the page, but when it finishes uploading the video, I get a message of "could not upload...timed out."

  • Sending bulk mail

    I am writing a program to send mails to 10k mail ids. My SMTP server provider has set a limit of 100 mails per hour for sending emails which is not sufficient for me. Can anybody provide me a solution? Does anybody know a public SMTP server without a

  • Different between initial replication and delta replication

    Hi, What is different between initial replication and delta replication of the catalog to B2B? Denis Khveshchenik