Removing offending characters from string...

Hello. I have some code that receives a csv file that is generated by an AS/400 - info about store orders, etc. However occasionally there is a character that causes an exception when I try to send the data into XML (prep for a web service call).
So, I added some code to my process to check the individual bytes. It's a byte value of 28 that causes me problems. I sometimes find it where I am expecting an apostrophe. So for testing purposes I added a routine that replaces byte=28 with an apostrophe, and all is well.
My question revolves around the fact that I don't have a great understanding of character encoding, etc. Essentially, what should I be doing? Should I be using different character encoding when reading the file (currently using ISO8859-1)? I don't have much control over the actual XML generation, so my hands are tied on that end. It just seems that the solution that I implemented is less-than-ideal. (Although searching through this forum, I did find it as a suggestion...)
Any help is greatly appreciated.
Chris

So any thoughts on the question of how to get rid of it?
Just iterate over all bytes as I am now? Or is there a better solution?I assume you are using something like a buffered reader to read in the CSV file contents. Does the ISO 8859-1 encoding have problems with the FS control code byte or does it simply read it in and decode it into \u0028 ? if the latter, my own inclination would be to handle it on the char level, (by replacement or removal) before you generate your XML. What you replace it with depends on its original function within the CSV file, which I don't know.
Joe

Similar Messages

  • 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!!!

  • How to remove new line from string

    I have a string say following
    String line = "one\ntwo\nthree";Now i am trying to remove new line from string. For this i did following
    String txt = line.replaceAll("\\n","");But i see still new line is occuring. Is it correct way. Please advice me.

    Ok. I was just using \n instead of \r\n. And i am in windows. I will give a try with \r\n
    Ok i tried using following , but it doesnt work.
    line = line.replaceAll("\\r\n","");Am i missing anything here. Please guide me.
    Edited by: ArpanaK on Oct 8, 2007 4:44 PM

  • Removing \r\n from string

    Hello, how do I remove the "\r\n" newline characters from a
    string in AS3 ?
    I can do it in Flex using StringUtil trim, but that is not
    available in Flash.
    Thanks for any help.

    Try something like this which replaces returns with a space:
    //grep to globally (gi) look for returns
    var returns:RegExp=/\r/gi;
    //your input text
    var str:String="the text";
    //return the clean text
    str.replace(returns," ");

  • Sql to remove special characters from my search

    Hi everyone.  I'm very new to sql and have hit another road block.  I am doing a query on my database in oracle sql developer.  I want to search manufacturer numbers but sometimes they were entered with dashes ( 999-99-9999) and other times not (999999999)  is it possible to apply a function to overlook the dash in both my query numbers and in the database mfr_nbr column?
    any help would be appreciated.
    Kelly

    ok,  I have built a nesting string of replaces to remove all of my special characters and it worked perfectly but now I am not sure where to place the nest later in the string to remove it from my search of mfr numbers.  The reason I need to do it again is because I want to remove the characters so I am searching in terms of " apples to apples" so to speak.   here is my string so far. I still need to add the part where I put in my search for the manuf_item_nbr.  my question is  where do I need to place the nested replace's to remove it from my numbers I'm going to search?
    SELECT  MAX(item_nbr) ,REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE( manuf_item_nbr, ' '), ','), '<'), '.'), '>'), '?'), ''), '"'), ';'), ':'), '\'), '|'), ']'), '}'), '['), '{'), '='), '+'), '_'), '-'), ')'), '('), '*'), '&'), '^'), '^'), '%'), '$'), '#'), '@'), '!'), '~'), '`'),
      manuf_item_nbr  ,MAX(description), MAX(description2), MAX(GHX_FULL_ITEM_DESCR), MAX(Cntrct_nbr_txt), MAX(uom_cd)   ,
    MAX(item_qty), MAX(tier_descr), MAX(tier_prc_amt),MAX(list_prc_amt), MAX(vndr_nm), MAX(vndr_id), MAX(unspsc_nbr),MAX(iss_account)   FROM
    ( SELECT '' AS item_nbr, manuf_item_nbr,'' AS description, '' AS description2,'' AS GHX_FULL_ITEM_DESCR, Cntrct_nbr_txt, uom_cd, CAST(item_qty AS VARCHAR (255)) AS item_qty,tier_descr, CAST ( tier_prc_amt AS VARCHAR (255)) AS tier_prc_amt, CAST (list_prc_amt AS VARCHAR (255)) AS list_prc_amt,
    vndr_nm, '' AS vndr_id, '' AS unspsc_nbr,'' AS iss_account FROM ROI.CNTRCT_PRC_LIST
    WHERE ACTN_CD <> 'D'
    AND ROW_UPDT_TSP IS NULL 
    UNION ALL
    SELECT item_nbr, manuf_item_nbr,'', '', GHX_FULL_ITEM_DESCR,'',  purch_uom_txt  AS uom_cd,
      purch_qoe_txt  AS item_qty, '',  '' AS tier_prc_amt,'' AS list_prc_amt,
    vndr_nm, vndr_id, unspsc_nbr,
      gl_cd  AS iss_account
      FROM ROI.ROI_ITEM_ENRCHD_NUVIA
       UNION ALL
    SELECT  trim(item)  AS item_nbr,
       trim(manuf_nbr)  AS manuf_item_nbr,
       trim(description),
       trim(description2), '' AS GHX_FULL_ITEM_DESCR, '',
        trim(stock_uom ) AS uom_cd,
        ''  AS item_qty,'', '','' AS tier_prc_amt, '' AS list_prc_amt,'' AS vndr_id, '' AS unspsc_nbr,
        CAST( trim(iss_account) AS VARCHAR(255))
          FROM ITEMMAST_LAW
    )GROUP BY manuf_item_nbr
       ORDER BY manuf_item_nbr

  • Problem with macro expansion removing ? characters from macros

    Hi,
    When compiling the following code (CC ex.cpp), we always receive the error line 28: Error: Unexpected ":" found.
    ex.cpp
    #include <stdio.h>
    #include <stdarg.h>
    #include <string.h>
    #define ONE 1
    #define MCheck(n) (n == ONE ? "One" : "???")
    #define F1(buff, size, ...) func(buff, size, __VA_ARGS__)
    #define F(...) F1(acBuff, sizeof(acBuff), __VA_ARGS__)
    void func(char* buff, size_t len, const char* fmt, ...) {
        va_list args;
        va_start(args, fmt);
        size_t nWrote = vsnprintf(buff, len, fmt, args);
        va_end(args);
    int main(void) {
        char acBuff[10];
        // Parsed OK
        F1(acBuff, sizeof(acBuff), "%s\n", MCheck(1));
        printf("%s", acBuff);
        // Causes error
        F("%s\n", MCheck(1));
        printf("%s", acBuff);
        return 0;
    }This appears to be because the pre-processed code (found using CC -E ex.cpp) has removed the '?' characters from the parsed macro 'F' expansion as shown:
    (Code inserted from headers)
    #13 "ex.cpp"
    void func ( char * buff , size_t len , const char * fmt , ... ) {
    va_list args ;
    ( void ) ( args = ( __va_list ) & __builtin_va_alist ) ;
    size_t nWrote = vsnprintf ( buff , len , fmt , args ) ;
    ( void ) 0 ;
    int main ( void ) {
    char acBuff [ 10 ] ;
    func ( acBuff , sizeof ( acBuff ) , "%s\n" , ( 1 == 1 ? "One" : "???" ) ) ;
    printf ( "%s" , acBuff ) ;
    func ( acBuff , sizeof ( acBuff ) , "%s\n" , ( 1 == 1 "One" : "???" ) ) ;
    printf ( "%s" , acBuff ) ;
    return 0 ;
    }Is this an error with the compiler, or is there some flag we need to set to ensure the macros are expanded to the correct level?

    Bwadly wrote:
    Hi Maxim,
    Thanks for the feedback.
    We are using Solaris 8, so I'm guessing we should use Sun Studio 11? Correct, the latest release that supports Solaris 8 is Sun Studio 11. Be sure to patch both Solaris and Sun Studio once you install it.
    BTW, I was able to reproduce the problem using Studio 9 compiler (CC 5.6). Apparently, it got fixed in later versions of compiler - patched version of CC 5.6 does not have it.
    Edited by: MaximKartashev on 15.08.2008 12:55

  • Best way to remove unwanted signs from string

    Which is the best way to purify a string from possible dangerous signs? I want to remove all characters that is not a-z or 0-9? how would I go about?

    read the string character by character, and check to
    see if they're characters you want to remove or not,
    by comparing them to the ascii values of characters
    you permit. I've used this before, but I can't
    remember what exactly it permits, and I'm too lazy to
    look up the ascii table :) But this sort of thing
    works.
    int c = in.read();
    while(c!=-1){
    if((c<33)||(c<58&&c>44)){
         out.write(c);
    I thought about that too. But the values in the ASCII table... arn't they a little volatile to use? I mean, will my application work on other systems or systems with other languages?

  • How to remove the comma from string

    Hi,
    I Have string like below :
    String some1="123,44.22";
    I want to remove comma from string and final output should be 12244.22.
    public class getOut{
    public static void main(String args[]){
    String some1="123,44.22";
    getChars(int 0,some1.length(),char[] dst,0);
    can somebody in the forum give me idea how to remove comma from the String and
    have a string without comma.
    Thanks
    Jack

    int idx = oldString.indexOf(',');
    if(idx >= 0)   
          newString = oldString.substring(0, idx) + oldString.substring(idx + 1);or for jdk 1.4 and later
    str = str.replaceAll(",", "");

  • Remove LF characters from file names

    I have a folder full of files with filenames that contain LF character (ASCII code 10).  I want to use Automator's "Replace Text" funcion to remove these non printing characters from file names.  Is there a way to do it?
    If automator is not able to do this task, I will take a bash script or applescript solution as well...

    Take a look at: http://stackoverflow.com/questions/4417588/sed-command-to-fix-filenames-in-a-dir ectory
    (I changed  tr -d "\r\n" to tr -d "\n", but try both)
    for f in ~/Desktop/*
    do
        new="$(printf %s "$f" | tr -d "\n")"
        if [ "$f" != "$new" ]; then
            mv "$f" "$new"
        fi
    done

  • Strip Characters from String?

    Hi,
    How can I strip off some characters from the end of a string?
    I am not very good at regular expressions but perhaps I may not
    need one? Here is the data
    first_name_510
    last_name_2267
    I need a function that will strip off everything from the
    right including the underscore. I should be left with the below:
    first_name
    last_name
    Any help highly appreciated
    Regards

    if it is always an underscore, and always the last one, this
    should do
    the trick:
    #left(string, len(string)-len(listlast(string, "_"))-1)#
    string is assumed to be the variable holding your text
    Azadi Saryev
    Sabai-dee.com
    http://www.sabai-dee.com/

  • Extract 2 characters from string

    Hello,
    Can anyone help to create a formula to extract 2 characters from the left of "pp" in a field using CR XI?
    Field = {MainEstimateDetails.JobDescription} (string)
    Sample string details:
    "Annual Report 96pp & Cover 12345"  - want to be able to show only 96 (from 96pp)
    "CTP A4 4pp" - want to be able to show only 4 (from 4pp)
    The string length is variable and the "pp" will be in different places each time.
    It is probably very simple, but I cannot get it

    Hi, 
    You can use the InStr function for this.  InStr returns the position of the string your are looking for. 
    NumberVar myPosition;
    If InStr ({MainEstimateDetails.JobDescription}, "pp") > 0 Then
        myPosition := InStr ({MainEstimateDetails.JobDescription}, "pp")
    Else myPosition := 0;
    If myPosition <> 0 Then
        {MainEstimateDetails.JobDescription} [(myPosition - 2) To (myPosition - 1)]
    Else "";
    This is a bit longer than I would normally do it but... I use Instr to check if the field has "pp" in it.  If it does it will return the character position in the field and I pass that to my variable myPosition. 
    If myPosition has a value then it parses out the two characters before "pp". 
    Good luck,
    Brian

  • Help removing encoded html from string

    Hello,
    I am trying to remove all html from a user input string.
    something like this:
    <cfset string ="sample text &lt;a&gt;">
    I have tried:
    Replace(string , "<[^>]*>", "", "ALL")
    Replace(string , "&lt;br &##x2f;&gt;>", "", "ALL")
    Neither remove the html, can anyone help?

    The related functions for replacing strings using regular expressions are REReplace and REReplaceNoCase. For example,
    <cfset string ="sample text <a>">
    <cfoutput>#REReplace(string , "<[^>]*>", "", "ALL")#</cfoutput>

  • Remove special characters from incoming data

    Hi Varun, You could use either of below.. REG_REPLACE(YOUR_INPUT_STR,^[A-Za-z0-9 ],NULL)  -- Replaces all non-alphanumeric with null
       REG_EXTRACT(YOUR_INPUT_STR,[A-Za-z0-9 ]) -- Extracts only alphanumeric data -Rajani

    i have special character coming in the source data and i want to remove it before loading into target, currently i am getting one special character , it may come as some other type of special character  other than alpha numeric. so how to remove those special characters from data and load the alphanumeric data into target.

  • Removing unicode control characters from string

    Hi.
    I have a webservice where I return an object (with some strings) back to the client. The information is read from a database, and the string can sometimes contain invalid xml characters (like unicode 0x13). This results in an error when parsing the information at the client side.
    Is there someway a easy way to set up a filter or something that checks whether the string contains characters outside the valid range specified for XML's (lower than unicode 0x20 etc), and removes them/replace them with a different character?

    If you have to get rid of the control chars then       String someText = "a\nb\nc\td\re\r\nf";
            String someTextWithoutControlChars = someText.replaceAll( "[\u0000-\u0020]","");
            System.out.println(someTextWithoutControlChars);but like kaj says, some control chars are valid.

  • Removing characters from string after a certain point

    Im very new to java programming, so if this is a realy stupid question, please forgive me
    I want to remove all the characters in my string that are after a certain character, such as a backslash. eg: if i have string called "myString" and it contains this:
    109072\We Are The Champions\GEMINI
    205305\We Are The Champions\Queen
    4416\We Are The Champions\A Knight's Tale
    a00022723\We Are The Champions\GREEN DAYi would like to remove all the characters after the first slash (109072*\*We...) leaving the string as "109072"
    the main problem is that the number of characters before and after is not the always the same, and there is often letters in the string i want, so it cant be separated by removing all letters and leaving the numbers
    Is there any way that this can be done?
    Thanks in advance for all help.

    You must learn to use the Javadoc for the standard classes. You can download it or reference it on line. For example [http://java.sun.com/javase/6/docs/api/java/lang/String.html|http://java.sun.com/javase/6/docs/api/java/lang/String.html].

Maybe you are looking for

  • Crystal report : Export to Text format from BI Launch pad

    Hi, We are facing issue in exporting the Crystal report to text format option from BI Launch pad view mode. Currently BI launch pad doesn't support export to Text format option for crystal report in view mode. But export to text format option is feas

  • Bug in preview portal doesn't display database list in back up section

    There seems to be a bug in the website back up option in the new portal. Even if you have connection strings defined it says: "You don't have any databases defined in the connection strings for this website" Unless I'm doing something wrong?

  • Function Based Indexes - negative performance

    Has anyone run across any cases where they have had issues with Function Based Indexes negatively impacting performance?? We are trying to use function based indexes in 9i (NLS_SORT=GENERIC_BASELETTER) and 10g (NLS_SORT=BINARY_CI) for case insensitiv

  • Unprinted released purchase orders

    Hello forum, Is there any way from standard SAP (report) to watch, which purchase orders are released but they are NOT printed ? Thanks in advance.

  • Why does NI-9233 with IEPE microphone report 39dBA as minimum noise level?

    Hi, I have been using an ACO Pacific 1/2" IEPE microphone and preamp (7052SYS) with cDAQ and a 9233 IEPE module. The ACO mic is very similar to the G.R.A.S. 46AE (50mV/Pa) but with a 20mV/Pa sensitivity. Using this set-up in a hemi-anechoic chamber,