Non-numeric String formatting

Ok, I understand about numeric string formating (NumberFormat). But what I need help with is string formatting.
For example, I'm working on an app with fixed-length records. Let's take a name field. I need the string "John Doe" formatted to a 40-character field, right-justified. Can someone point me to a class or a URL with information on this.
Sorry for asking such an elementary question.

Ok, I understand about numeric string formating
(NumberFormat). But what I need help with is string
formatting.
For example, I'm working on an app with fixed-length
records. Let's take a name field. I need the string
"John Doe" formatted to a 40-character field,
right-justified. Can someone point me to a class or a
URL with information on this.In the JDK I found nothing, but in the jakarta-Projekt of apache.org:
http://jakarta.apache.org/commons/lang.html
There is a class called StringUtils.
You only have to write:
String rightJustified = StringUtils.rightPad("John Doe", 40);
If you don't find something in the JDK look at Jakarta. They have a lot of useful stuff.

Similar Messages

  • Ascii value of a non numeric string  literal

    hi,
    i would like to get the ascii value of a non numeric string
    having special characters from extended ascii set.
    for example i have a user id "J��o M��" and i want to get the ascii value of each character in this string.
    (There are special characters having ascii value more than 127, present in string literal)
    if you know some methods to do that ??
    thanks

    Use charAt(i) to give you each char in the string. A char is also the numeric value of the character: note that there's no such thing as "extended ASCII" -- ASCII is the first 128 characters of Unicode, and Java uses Unicode characters.
    String str = "Hello";
    for (int i = 0; i < str.length(); i++)
        System.out.println((int) str.charAt(i)); // cast to int so the char is displayed as a number

  • Getting non numeric strings using regular expression

    Hi Guys ,
    I  want to get list of string values in table which contains no numeric values  .....
    I have a   string column name A and table name B  .
    I have written following code , but it seems it is incorrect  .
    Plz help me out  .....
    SELECT
    A FROM
    B
    WHERE
    regexp_like(A, '([^[:digit:]])'
    Thanks in advance ....

    96097f0e-f165-463a-a0a2-3d15214c8a3d wrote:
    Hi Guys ,
    I  want to get list of string values in table which contains no numeric values  .....
    I have a   string column name A and table name B  .
    I have written following code , but it seems it is incorrect  .
    Plz help me out  .....
    SELECT
    A FROM
    B
    WHERE
    regexp_like(A, '([^[:digit:]])'
    Thanks in advance ....
    That will give you every one that has at least one non-numeric character, if you want ones which contain no numeric characters then it should be
    regexp_like(A,'^[^0-9]*$')

  • Select only non-numeric characters

    A
    $
    ^
    (78^*)5$#7
    )!@#$0-99
    _454*(&--0
    +@#$%564
    =123
    How select only non-numeric characters from above table?

    Nilesh Hole,Pune, India wrote:
    but i want a uniqe query.
    suppose table have n number of rows then how i will wirte a query.Not sure what you mean? Do you want to select a list of distinct non-numeric characters used in your table? Then:
    column "Distinct non-numeric chars" format a30
    with t as (
               select '!' a from dual union all
               select '@' from dual union all
               select '#' from dual union all
               select '$' from dual union all
               select '%' from dual union all
               select '^' from dual union all
               select '&' from dual union all
               select '*' from dual union all
               select '(78^*)5$#7' from dual union all
               select ')!@#$0-99' from dual union all
               select '_454*(&--0' from dual union all
               select '+@#$%564' from dual union all
               select '=123' from dual union all
               select '135790' from dual
    select  distinct substr(a,column_value,1) "Distinct non-numeric chars"
      from  (
             select  regexp_replace(a,'[[:digit:]]') a
               from  t
               where not regexp_like(a, '^[[:digit:]]+$')
            table(
                  cast(
                       multiset(
                                select  level
                                  from  dual
                                  connect by level <= length(a)
                       as sys.odcinumberlist
    Distinct non-numeric chars
    +
    =
    $
    Distinct non-numeric chars
    ^
    14 rows selected.
    SQL> SY.

  • Replace Non-Numeric Characters with a Numeric Character in a String

    Hi Guys,
    I need to replace all the non-numeric characters (including embedded blanks & hyphen) in a string to a numeric character '1'.
    The trailing blanks should not be replaced.
    e.g. "P22233344455566" should be changed to "122233344455566"
    &    "49-1234567           " should be changed to "4911234567          "
    Please help.

    Use [replace|http://help.sap.com/abapdocu_70/en/ABAPREPLACE_IN_PATTERN.htm] with a regular expression to translate any non-numeric character (i.e. any character not between 0 and 9) to 1:
      REPLACE ALL OCCURENCES OF REGEX '[^0-9]' IN value WITH '1'.
    Cheers, harald
    p.s.: In older releases [translate|http://help.sap.com/abapdocu_70/en/ABAPTRANSLATE.htm] would also do the trick, but is more lengthy, because one would need to specify each individual character that should be replaced, e.g.:
      TRANSLATE value TO UPPER CASE.
      TRANSLATE value USING
          ' 1_1-1a1b1c1d1e1f1g1h1i1j1k1l1m1n1o1p1q1r1s1t1u1v1w1x1y1z1'.

  • Find a non-numeric character in a string

    I have a 3 strings (1) 'AB99CDEFGH0012%' (2) 'ABCDEFGH' (3) 'ABCD11'
    how do i find out a that string has non numeric characters
    Thanks

    SELECT TO_NUMBER(:String) FROM DUAL;
    is a quick way to find out :)
    A good method would be.....
    SELECT 1 FROM DUAL WHERE TRANSLATE(:String, 1234567890, '-') IS NOT NULL;
    The statement will filter out ALL numbers, leaving behind any characters, A, B, @, ~, etc...

  • Removing non-numeric characters from string

    Hi there,
    I need to have the ability to remove non-numeric characters from a string and I do not know how to do this.
    Does any one know a way?
    Example:
    Present String: (02)-2345-4607
    Required String: 0223454607
    Thanks in advance

    Dear NickM
    Try this this will work...........
    create or replace function char2num(mstring in varchar2) return integer
    is
    -- Function to remove Special characters and alphebets from phone no. string field
    -- Author - Valid Bharde.(India-Mumbai)
    -- Date :- 20 Sept 2006.
    -- This Function will return numeric representation.
    -- The Folowing program is gifted to NickM with respect to his post on oracle site regarding Removing non-numeric characters from string on the said date
    mstatus number :=0;
    mnum number:=0;
    mrefstring varchar2(50);
    begin
    mnum := length(mstring);
    for x in 1..mnum loop
    if (ASCII(substr(upper(mstring),x,1)) >= 48 and ASCII(substr(upper(mstring),x,1)) <= 57) then
    mrefstring := mrefstring || substr(mstring,x,1);
    end if;
    end loop;
    return mrefstring;
    end;
    copy the above program and use it at function for example
    SQL> select char2num('(022)-453452781') from dual;
    CHAR2NUM('(022)-453452781')
    22453452781
    Chao!!!

  • String is non numeric

    Hello,
    My customer is using Crystal X1. I created a report for them with the following parameter to choose either a date or year period. The report works on my laptop, however, when I copy it to their environment I receive the error 'String is non numeric' if they chose year and period.
    And ideas ?
    If {?SELECTTRANBY} = "0" Then
    {ICIVAL.TRANSDATE} <= ToNumber({?TODATE})
    Else
    ({ICIVAL.FISCYEAR} < {?TOYR} OR
    ({ICIVAL.FISCYEAR} = {?TOYR} AND
    {ICIVAL.FISCPERIOD} <= ToNumber({?TOPR})))
    Thanks,
    Debbie

    Try changing it to:
    If {?SELECTTRANBY} = "0" Then
    {ICIVAL.TRANSDATE} <= ToNumber({?TODATE})
    Else
    {ICIVAL.FISCYEAR} < {?TOYR} OR
    {ICIVAL.FISCYEAR} = {?TOYR} AND
    {ICIVAL.FISCPERIOD} <= if isnumeric(Trim({?TOPR})) then Tonumber({?TOPR})
    P.S: I hope the users enter just numbers in the {?TOPR} prompt
    -Abhilash

  • Removing Non-numeric characters from Alpha-numeric string

    Hi,
    I have one column in which i have Alpha-numeric data like
    COLUMN X
    +91 (876) 098 6789
    1-567-987-7655
    so on.
    I want to remove Non-numeric characters from above (space,'(',')',+,........)
    i want to write something generic (suppose some function to which i pass the column)
    thanks in advance,
    Mandip

    This variation uses the like operators pattern recognition to remove non alphanumeric characters. It also
    keeps decimals.
    Code Snippet
    CREATE FUNCTION dbo.RemoveChars(@Str varchar(1000))
    RETURNS VARCHAR(1000)
    BEGIN
    declare @NewStr varchar(1000),
    @i int
    set @i = 1
    set @NewStr = ''
    while @i <= len(@str)
    begin
    --grab digits or (| in regex) decimal
    if substring(@str,@i,1) like '%[0-9|.]%'
    begin
    set @NewStr = @NewStr + substring(@str,@i,1)
    end
    else
    begin
    set @NewStr = @NewStr
    end
    set @i = @i + 1
    end
    RETURN Rtrim(Ltrim(@NewStr))
    END
    GO
    Code to validate:
    Code Snippet
    declare @t table(
    TestStr varchar(100)
    insert into @t values ('+91 (8.76) \098 6789');
    insert into @t values ('1-567-987-7655');
    select dbo.RemoveChars(TestStr)
    from @t

  • How can I Convert a numeric string to a formatted string?

    I have a string value returned from a background tool that will range from 0 to possibly terabytes as a full number.  I want to format that number to use commas and to reduce the character count using an appropriate size modifier (KiB, MiB, GiB, etc).  I've tried converting the string number to a Double value using Double.parseDouble() and then performing the math based on the size of the value with this code:
    Double dblConversionSize;
    String stCinvertedSize;
    dblConversionSize = Double.parseDouble(theValue);
    if (dblConversionSize > (1024 * 1024 * 1024))
         stConvertedSize = String.format("%,.000d", dblConversionSize / 1024 / 1024 / 1024) + " TiB";
    I've also tried using
         String.valueOf(dblConversionSize / 1024 / 1024 / 1024) + " TiB";
    However, the formatting is failing and I'm either getting a format exception or the result is displayed as a number with no decimal component.
    Anyone have a recipe for this?
    Thanks,
    Tim

    TOLIS Tim wrote:
    Thanks, but the reason for using Double is that the division math can leave me with values like 2.341 GiB.  I don't want to drop the values (or round) on the right side of the decimal point.
    Then you may look for DigDecimal which avoids digitization errors.
    NumberFormat will handle all subclasses of Number. You might need another specialization. Just look at the API which one is suitable.
    bye
    TPD

  • Converting string format of a number to numeric.

    Hi,
    I use the NumberFormat classes to convert a number to it's string formatted representation in the given locale. How do I achieve the opposite?
    I mean, how do I convert a String value of +"23,233,23"+ to an integer value 2323323?
    Thanks.

    I use the NumberFormat classes to convert a number to it's string formatted representation in the given locale. How do I achieve the opposite?Have a look at the parse() method of NumberFormat.
    ~

  • Sqlldr with error: non-numeric character was found when numeric number

    Hi,
    I have been struggling with this problem for long, can't get to anywhere.
    I am trying to use sqlldr to load a CSV file into table, the table looks like this :
    AD_ID NUMBER(38)
    CNTCT_ID VARCHAR2(60)
    AD_FILE_NAME VARCHAR2(80)
    AD_TITLE VARCHAR2(300)
    AGCY_APRVL_DATE DATE
    CORE_APRVL_DATE DATE
    ENTR_CMNT CLOB
    IC_APRVL_DATE DATE
    PURP_TEXT CLOB
    RVW_BRD_APRVL_DATE DATE
    ACTIVE_FLAG VARCHAR2(1)
    .......................................more fields
    The control file looks like this:
    LOAD DATA
    INFILE "C:\ORACLE_IRTMB\IRPADS\SQL_DATA\ADS_T.CSV"
    BADFILE "C:\ORACLE_IRTMB\IRPADS\ADS_T.BAD"
    DISCARDFILE "C:\ORACLE_IRTMB\IRPADS\ADS_T.DSC"
    truncate INTO TABLE ADS_T
    FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS
         AD_ID INTEGER ,
         CNTCT_ID char ,
         AD_FILE_NAME char ,
         AD_TITLE char nullif (AD_TITLE=BLANKS) ,
         AGCY_APRVL_DATE DATE "MM/DD/YYYY" nullif (AGCY_APRVL_DATE=BLANKS) ,
         CORE_APRVL_DATE DATE "MM/DD/YYYY" ,
         ENTR_CMNT CHAR(7000) nullif (ENTR_CMNT=BLANKS) ,
    PURP_TEXT CHAR(7000) nullif (ENTR_CMNT=BLANKS) ,
         RVW_BRD_APRVL_DATE DATE "MM/DD/YYYY" ,
         ACTIVE_FLAG char ,
         ....more fields
    The Data file looks like this:
    10132,simpsonl,PMSDHHStemplate.pdf,"Depression, Irritability, Mood Swings Sound Familiar?",1/13/2003,11/14/2002,,1/13/2003,"The NIMH is conducting research on premenstrual
    10133,jolkovsl,10133ClozapineDHHS ver 0.pdf,Mood Swings? Unpredictable Moods? Are These Moods hard to Treat?,1/28/2003,11/14/2002,,1/28/2003,"The NIMH is conducting a study to test the efficacy of ...
    --- and log file looks like this:
    Record 5: Rejected - Error on table ADS_T, column RVW_BRD_APRVL_DATE.
    second enclosure string not present
    Record 7: Rejected - Error on table ADS_T, column RVW_BRD_APRVL_DATE.
    second enclosure string not present
    Record 9: Rejected - Error on table ADS_T, column RVW_BRD_APRVL_DATE.
    second enclosure string not present
    Record 2: Rejected - Error on table ADS_T, column AGCY_APRVL_DATE.
    ORA-01858: a non-numeric character was found where a numeric was expected
    Record 4: Rejected - Error on table ADS_T, column AGCY_APRVL_DATE.
    ORA-01858: a non-numeric character was found where a numeric was expected
    Record 6: Rejected - Error on table ADS_T, column AGCY_APRVL_DATE.
    ORA-01858: a non-numeric character was found where a numeric was expected
    IF I use to_date in control file:
    LOAD DATA
    INFILE "C:\ORACLE_IRTMB\IRPADS\SQL_DATA\ADS_T.CSV"
    BADFILE "C:\ORACLE_IRTMB\IRPADS\ADS_T.BAD"
    DISCARDFILE "C:\ORACLE_IRTMB\IRPADS\ADS_T.DSC"
    truncate INTO TABLE ADS_T
    FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS
         AD_ID INTEGER ,
         CNTCT_ID char ,
         AD_FILE_NAME char ,
         AD_TITLE char nullif (AD_TITLE=BLANKS) ,
         AGCY_APRVL_DATE "to_date(:AGCY_APRVL_DATE,'MM/DD/YYYY')" ,
         CORE_APRVL_DATE DATE "MM/DD/YYYY" ,
         ENTR_CMNT CHAR(7000) nullif (ENTR_CMNT=BLANKS) ,
         IC_APRVL_DATE DATE "MM/DD/YYYY" ,
         PURP_TEXT CHAR(10000) nullif (PURP_TEXT=BLANKS) ,
         RVW_BRD_APRVL_DATE DATE "MM/DD/YYYY" ,
    I got extracctly same error message as above...
    If I use to_char in control file:
    LOAD DATA
    INFILE "C:\ORACLE_IRTMB\IRPADS\SQL_DATA\ADS_T.CSV"
    BADFILE "C:\ORACLE_IRTMB\IRPADS\ADS_T.BAD"
    DISCARDFILE "C:\ORACLE_IRTMB\IRPADS\ADS_T.DSC"
    truncate INTO TABLE ADS_T
    FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' TRAILING NULLCOLS
         AD_ID INTEGER ,
         CNTCT_ID char ,
         AD_FILE_NAME char ,
         AD_TITLE char nullif (AD_TITLE=BLANKS) ,
         AGCY_APRVL_DATE "to_char(:AGCY_APRVL_DATE,'MMDDYYYY')" ,
    Then it's said a not valid number
    Record 2: Rejected - Error on table ADS_T, column AGCY_APRVL_DATE.
    ORA-01722: invalid number
    Record 4: Rejected - Error on table ADS_T, column AGCY_APRVL_DATE.
    ORA-01722: invalid number
    Record 6: Rejected - Error on table ADS_T, column AGCY_APRVL_DATE.
    ORA-01722: invalid number
    Record 8: Rejected - Error on table ADS_T, column AGCY_APRVL_DATE.
    ORA-01722: invalid number
    someone, please help me out here.
    Thanks a lot.
    Wei

    hello
    pls use to_date
    If your session is set to default date format of DD-MON-YY, execute the following and you will receive the error message:
    SQL> select to_date('20-JAN-2010', 'DD-MM-YYYY') from dual;
    ERROR:
    ORA-01858: a non-numeric character was found where a numeric was expected
    no rows selected
    When you are converting a string to a date, you have specified that the date is being passed in DD-MM-YYYY format. But you have passed the date in DD-MON-YYYY format. As the month is expected as a number by oracle, but you have passed a character, oracle is unable to translate the string to a number.
    Do one of the following:
    SQL> select to_date('20-JAN-2010', 'DD-MON-YYYY') from dual
    2 /
    TO_DATE
    20-JAN-2010
    OR
    SQL> select to_date('20-10-2010', 'DD-MM-YYYY') from dual
    2 /
    TO_DATE
    20-JAN-2010
    or you can use alter sessin set nls_date_format='.....................';
    regards

  • A non-numeric character was found ...  iAS 8 & ora 8.1.6

    I have a problem in iAS 8 and Oracle 8.1.6 under windows 2000.
    The problem is calling nested packages using plql gateway, I
    mean I call one package and it call's another package, this
    operation throws " a non-numeric character was found where a
    numeric was expected" even if the procedure only has one
    parameter, if you call nested procedures there are no errors, I
    had the same problem on Solaris, however changed databases and
    it dissapear, I thought that the problem was some
    NLS_PARAMETERS however now I'm not pretty sure.
    Any Ideas.
    Thanks in Advance.
    Francisco Castaqeda
    Arango Software Int.

    hello
    pls use to_date
    If your session is set to default date format of DD-MON-YY, execute the following and you will receive the error message:
    SQL> select to_date('20-JAN-2010', 'DD-MM-YYYY') from dual;
    ERROR:
    ORA-01858: a non-numeric character was found where a numeric was expected
    no rows selected
    When you are converting a string to a date, you have specified that the date is being passed in DD-MM-YYYY format. But you have passed the date in DD-MON-YYYY format. As the month is expected as a number by oracle, but you have passed a character, oracle is unable to translate the string to a number.
    Do one of the following:
    SQL> select to_date('20-JAN-2010', 'DD-MON-YYYY') from dual
    2 /
    TO_DATE
    20-JAN-2010
    OR
    SQL> select to_date('20-10-2010', 'DD-MM-YYYY') from dual
    2 /
    TO_DATE
    20-JAN-2010
    or you can use alter sessin set nls_date_format='.....................';
    regards

  • Returning Non-Numeric character

    Hi All,
    Im using Oracle 11gR2. Following is my sample data and i want to search the string having non-numeric characters in it.
    with t as
    select '123' val from dual
    union
    select ' 123' val from dual
    union
    select '1123' val from dual
    union
    select 'A123' val from dual
    union
    select 'x 123' val from dual
    union
    select '#123' val from dual
    select val from t
    where regexp_like (val, '[[:alpha:]|[:blank:]|#]')Query works perfectly for given result set but would break if another string, say '123@', with a special character comes. So is there any format specifier (as we have [:alpha:], [:digit:]) to directly identify non-numeric character including space from a string? If no what is the work round for it?
    Thanks,
    Vivek

    Vivek wrote:
    Query works perfectly for given result set but would break if another string, say '123@', with a special character comes. So is there any format specifier (as we have [:alpha:], [:digit:]) to directly identify non-numeric character including space from a string? If no what is the work round for it?What is your expected output?
    All the strings which contains anything other than digits? You could use TRANSALTE
    select val from t
    where translate(val,'a0123456789','a') is not null;
    --"Add space also if you want to exclude space
    select val from t
    where translate(val,'a 0123456789','a') is not null;
    {code}
    You could use REGEXP_LIKE or REGEXP_REPLACE, but regexp functions are more CPU consuming..
    {code}
    select val from t
    where not regexp_like(val,'^0-9+$');
    {code}
    Edited by: jeneesh on Apr 2, 2013 2:16 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Error while pulling data from an Oracle database. ORA-01858: a non-numeric character was found where a numeric was expected

    I'm trying to pull data from an Oracle database using SSIS. When I try to select a few fields from the source table, it returns the following error message:
        [OLE DB Source [47]] Error: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80040E14.
        An OLE DB record is available.  Source: "OraOLEDB"  Hresult: 0x80040E14  Description: "ORA-01858: a non-numeric character was found where a numeric was expected".
        An OLE DB record is available.  Source: "OraOLEDB"  Hresult: 0x80004005  Description: "ORA-01858: a non-numeric character was found where a numeric was expected".
    The source columns are a combination of numeric and texts, and I've also tried selecting one of them, which didn't work. I'm using the Oracle client 11.2.0.1, and it works fine with any other data sources I have connected to so far. How can I resolve this
    error?

    Hi H.James,
    According to your description, the issue is a non-numeric character was found where a numeric was expected while pulling data from an Oracle database in SSIS.
    Based on the error message, the issue should be you are comparing a number column to a non-number column in a query. Such as the query below (ConfID is a number, Sdate is a date):
     where C.ConfID in (select C.Sdate
                       from Conference_C C
                       where C.Sdate < '1-July-12')
    Besides, a default behavior for the Oracle OleDb Provider that change the NLS Date Format of the session to 'YYYY-MM-DD HH24:MI:SS can also cause the issue. For more details about this issue, please refer to the following blog:
    http://blogs.msdn.com/b/dataaccesstechnologies/archive/2012/01/20/every-bug-is-a-microsoft-bug-until-proven-otherwise.aspx
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

Maybe you are looking for

  • Report to check project-wbs-requesting co.code-company code in assignment

    Dear All, Is there any standard report to check Requesting co.code and company code (assignment tab) by project and wbs. I tried CNS43 but there is no requesting company code. Can we use SQ01 to create this one ? Any one can advice me how to make que

  • How do I transfer my itunes library to a new computer from my iPhone. The old one no longer works.

    How do I transfer my itunes library to a new computer from my iPhone. The old computer no longer works.

  • Run OS command

    hi,   I need to run unix script before file comming into PI .Script will do some convertion and place file in respective dir .Later Sender channel will convert that file(non xml format to XML) and post file into target.   we need to select run os com

  • Writing data from PLC to XLS file

    I am trying to write data from a PLC to an XLS file, i can write data when its generated, but wheni read from a DataSocket i cant seem to write it to the XLS file... i have attached what i've done please let me know what you think... any corrections

  • Paste Link 'Outline Level' from Excel into Project get error

    I am trying to generate a MS Project schedule based on linked data in an Excel spreadsheet. I cannot get the summary project tasks to appear with their sub-tasks. When I try to paste link the Outline Level into Project, I get and error that states "T