Replacing windows new line characters with JAVA

I am importing a file into the database... the file is written by a client using windows, and it is a text file.
When there is a windows new line character at the end of the line (^M), it is getting saved to the database as part of the string value.
When we parse this data to run a report, the (^M) are being written back out to the file and causing the fields and data not to line up.
We want to REPLACE the ^M with some other character (whatever it doesn't matter)... how can java do that???
We tried replacing '/n' with '###' and it will show the ###, but the line still breaks.
TIA,
Tonya

The characters in question are cr = \r = ascii(13) and lf = \n = ascii(10). Windows uses CrLf, Unix uses Lf and some systems use just Cr. You can use the String.replaceAll or the pattern matching classes to fix this up, see java.util.regex.Pattern, and java.util.regex.Matcher.

Similar Messages

  • Replacing multiple new line characters

    how to replace multiple new line characters in a line.
    Suppose for example my line contains Example1#####Example2##Example3###Example4,
    then the output should be Example1#Example2#Example3#Example4.

    Hi Sid,
    You Can try this code
    DATA: ld_string TYPE string,
          ld_string1 TYPE string,
          ld_string2 TYPE string,
          ld_string3 TYPE string.
    ld_string = 'Example1#####Example2##Example3###Example4'.
    REPLACE ALL OCCURRENCES OF '######' in ld_string with '#'.
    REPLACE ALL OCCURRENCES OF '####' in ld_string with '#'.
    REPLACE ALL OCCURRENCES OF '###' in ld_string with '#'.
    REPLACE ALL OCCURRENCES OF '##' in ld_string with '#'.
    write:/1 ld_string.
    Regards
    Pavan

  • Finding New Line characters in string

    Hello.
    I have a textstring in which there are New Line characters. These cause problems when inserting the data.
    An example is as follows (assume a table test exists with one column col1 VARCHAR2(2000):
    CREATE TABLE test (col1 VARCHAR2(2000));
    INSERT INTO test (col1) VALUES ('first line
    second line');
    INSERT INTO test (col1) VALUES ('first line' ||
    chr(10) ||
    'second line');
    The first INSERT will fail but the second will succeed.
    I want to find and replace these characters programatically in PL/SQL.
    How can I edit a textstring in PL/SQL and replace the new line characters with ||
    chr10) ||?
    /Lars

    How about this:
    declare
    v_oldstring VARCHAR2(50) := 'Line1'||chr(10)||'Line2'||chr(10)||'Line3';
    v_tmpstring VARCHAR2(50);
    v_newstring VARCHAR2(50);
    begin
      dbms_output.put_line(v_oldstring);
      select replace(v_oldstring, chr(10), '''||chr(10)||''')
      into v_tmpstring
      from dual;
      v_newstring := ''''|| v_tmpstring || '''';
      dbms_output.put_line(v_newstring);
    end;

  • Force Windows New Line Character

    Hi,
    I've a problem with new line character. I am in Windows platform but
    when I write a file with a BufferedWitter with println I obtain the
    character "\n" x0D like separator (Unix Separator). My System property
    line.separator is "\r\n".
    Can someone tell me how can I obtain files with the correct \r\n
    Windows new line character?.
    Thanks in advance.

    Resolved
    The problem was another process that automatically was replacing "\r\n" form "\n" and I don�t know it.
    All works fine.
    Thanks a lot.

  • Problem with new-line-character and java.io.LineNumberReader under AIX

    Hi folks,
    I got the following problem: I wrote a little parser that reads in a plain-text, tabulator-separated, line-formatted logfile (and later on safes the data to a 2-dimensional Vector). This logfile was originally generated by an AIX ksh script, however, I copied it on my Windows machine to work with it (for I'm using a Java editor that runs under Win Systems).
    For any reason, Windows, and what is worse Java too, seems not to recognize correctly the new-line character (in the API it is written that this should be a newline '\n' or a carriage-return '\r' or one followed by the other) that marks the end of a line in the logfile.
    Also, when I'm opening the logfile with the "Notepad"-editor, this special character does not seem to be recognized, every line is inserted right after the other.
    On the other side, when I open the logfile with the built-in editor in the CMD-Shell ("Dos-shell"), the newline chars seem to be recognized correctly.
    But when start my parser on the AIX-machine the newline does not seem to be recognized correctly again.
    I tried to read in the logfile with MS-Excel and safe it as a plain-text, tabulator-separated, line-formatted logfile again, with such files my parser works fine both on the AIX as it does on Windows.
    Any ideas? Anybody got over the same problem already?
    Greetz FK

    Under windows, text files' lines are usually delimited by \r\n,
    under Unix/Linux/AIX etc. \n
    and under Mac \r.
    I recommend to use the following editors, which are capable to handle files with Unix and Windows-styled line-delimiters or convert between these types:
    Programmer's File Editor (PFE; available on Windows)
    The Nirvana Editor (http://www.nedit.org/; available on Unix, MAcOS, Windows)
    (BTW good old vim can handle that too. Transferring text files to windows in order to edit them, even using Excel for this purpose means your being a UNIX newbie, (I mean no offense by writing this) so vim is probably beyond your reach for the moment.)
    Java normally assumes the platform's line delimiters where it is running, so if you transferred the file from Unix to Windows might be distrurbing.

  • How to write this logic  in EL expression ? (new line characters in string

    iam using JSTL EL expression in my JSP.
    iam printing a string in JSP as ${vobject.rmessage} where rmessage is a string .
    problem is i want to identify the newline characters in the above rmessage string and print the line break <br> in html where ever the new lines character is present in the string.
    How should i write an EL expression for the above.
    Can anyone please guide me on writing EL expression for the above problem?

    Several ways. You can wrap the output with <pre> tags. You can apply CSS property white-space: pre; to the element. You can use String#replaceAll() in the Java code to replace each occurence of "\r\n" by "<br>".

  • Detecting new line characters

    How do I detect new line and carriage return characters with
    string functions like replace? It works if I actually insert a new
    line in the function by pressing return, but that messes up the
    formatting and makes reading the code less intuitive.

    You may need to look for both chr(10) and chr(13) depending
    on O/S. On *NIX you're likely to need to check for both.

  • JMenuBar display quirks with some window managers on Linux with Java 6

    When I run this code on Windows with Java 5 or Java 6, it works fine.
    When on Linux with Java 5, it works fine.
    When on Linux with Java 6 in KDE, it works fine.
    When on Linux with Java 6 with twm or e17, the JMenu shows when I click on the JMenuBar, but goes away as soon as I release the mouse button. If I manually move or resize the window, it then works fine.
    If I remove setLocationByPlatform(true), the menu bar works, but it does not position the window by platform, which is the desired behavior.
    Am I doing something wrong, is there something wrong with both twm and e17, or is this a bug?
    import java.awt.Dimension;
    import java.awt.Label;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JFrame;
    import javax.swing.JMenuBar;
    import javax.swing.JMenu;
    import javax.swing.JMenuItem;
    import javax.swing.WindowConstants;
    public class Test extends JFrame {
        public Test() {
            super();
            setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE );
            getContentPane().add( new Label( "Hello World" ) );
            JMenuBar mainMenu = new JMenuBar();
            setJMenuBar( mainMenu );
            JMenu helpMenu = new JMenu();
            mainMenu.add( helpMenu );
            helpMenu.setMnemonic( 'H' );
            helpMenu.setText( "Help" );
            JMenuItem help_about = new JMenuItem();
            helpMenu.add( help_about );
            help_about.setMnemonic( 'A' );
            help_about.setText( "About" );
            help_about.addActionListener(
                new ActionListener() {
                    public void actionPerformed( ActionEvent evt ) {
                        System.out.println( "HELP!" );
            pack();
            setLocationByPlatform( true );
            setVisible( true );
        public static void main( String[] args )
            throws Exception {
            java.awt.EventQueue.invokeLater(
                new Runnable() {
                    public void run() {
                        Test test = new Test();
    }

    In 10.1.3, there's an option to disable the splash screen on the Environment Page in preferences (although, of course, it's not much use if you never get to the main window because of the dialog popping up behind the splash screen... :) )
    The bug with the dialog appearing behind the splashscreen is fixed in the upcoming 11g release. FWIW, it's a problem that appears to be unique to X-based systems, where for some reason the splashscreen window ends up with some super-ueber topmost property that forces all other windows to go behind it.
    There's also a command line flag to suppress the splashscreen in 11g.
    Thanks,
    Brian

  • Finding nr of "new-line"-characters in string

    Hi!
    I looking for a smooth way of achieveing the number of "\n" characters in a string.
    e.g.
    String tmp = "There is a house\n in New Orleans, \n they call the Rising Sun\n";
    This string should return number 3 (three occurrences of the '\n' character.
    How ?
    /Rickard

    I'm not sure if this is the best way to do this but it works ok,
    String tmp = "There is a house\n in New Orleans, \n they call the Rising Sun\n";
    java.util.StringTokenizer st = new java.util.StringTokenizer(tmp, System.getProperty("line.separator"));
    int counter = 0;
    while(st.hasMoreTokens()) {
         st.nextToken();
         counter++;
    }

  • Create new oracle database with JAVA

    Hi!
    I would appreciated it if you could help me to solve a problem that i have.
    I am trying to create a new oracle database by a JAVA 1.4.2 application. I am using the scripts that Oracle 10.g supplies during the creation of a new database from the server (Generate Database Creation Scripts) with the appropriate changes, generated by a java application. Unfortunately, i am unable to connect with the database and the listener. Is there any other way to create a new database by java and how can i solve my current problem with the oracle scripts?
    Thank you.

    A) To create a new schema, you need to be connected as a user that has create schema privilege, or as tyhe user who is to own the schema (remembering that the user has appropriate create privs, as seen in the GRANT command in the SQL Reference manual). Not an issue at all, I think, if you coordinate this with your DBA. Discussed very well in the Administrator's manual.
    B) Alternately, you could create a complete copy of the schema, including all desired objects (tables, views, etc.) in a separate database and simply export the user and schema. Then simply invoke the OS-based import command (imp) to load that entire thing into the target database.
    C) To create a new database, there are 3 simple steps ...
    1) create the appropriate initialization parameter file
    the init{sid}.ora file should be placed in the $ORACLE_HOME/dbs or %ORACLE_HOME%\database directory. (I recommend you do not attempt to create the spfile.) Of critical interest will be setting the block size information, the control file parameters, and using the appropriate memory management parameters, based on the version of the software you will be using to create the database instance.
    2) start an empty instance, pointing to the parameter file
    This will be an OS specific call, and will require that you have the correct OS environment set up as well as access to the ORACLE_HOME which will provide the software that you will invoke. In *nix you will need to call the sqlplus command with sysdba provs and in Windows you will need to call oradim to initialize this as a service.
    3) run the SQL create database command
    You might want to use the dbca to create a template of the create database command, or look in the SQL Reference manual for the variations on the command. Of critical interest will be initializing the redo logs as well as the system, sysaux (if needed), temp and undo tablespaces after which you can set up the regular tablespaces, users and schemas. I highly recommend that you have redundant copies of the control files on separate drives.
    You may want to review the online Concepts manual and the Adminstration Guide for some of the specifics to your needs, but I think I've covered the basics.
    Remember that ideally you will only have one database instantiated on any given server as the memory and CPU overhead of each instance is significant.
    Good luck.

  • Windows and Mac hostnames with Java.

    Hi,
    I'm not sure if this is the correct board or not for this, but I'm really getting frustrated, and I'm sure it's something easy for someone who knows.
    Anyway.. I'm working on some Java software for school, and I'm trying to get the program to run on my 2 machines (one is the MBP, and the other is a windows XP pc), but I'm having trouble having trouble finding one machine from the other (in either direction) because neither can seem to find the hostname of the other.
    On my Mac, from the Sharing panel I have set my local hostname to david.local. On my windows box, my hostname is david. I can ping myself on each machine, but when I try to hit the other, the hostname can't be found.
    Please help me figure this out. I know it has something to do with the naming, because I gotten this to work a couple of years ago for another project. Only.. it's been a while and I hadn't had to do it since then, so I've forgotten what I had to do back then to get it working.
    Any help with be greatly appreciated!
    David

    Hi Rick,
    I changed the Mac so it would be on Mshome (yes, I left it as the default in windows.. lol.)
    Rebooted both.. no dice.
    A question about this though.. can I still connect to other networks? I take my computer to school, and I have never had to change this before, and everything had worked smoothly.
    Oh! That reminds me. I can connect to shared folders on my Windows machine from my Mac with the Connect to Server from Finder. I do smb://david/<shared folder> and it all worked out just fine, without the workgroup being set. (Still works now, btw)
    Thanks,

  • Using Command Line Arguments with JAVA

    Hi,
    we are using an app called ImageMagick to scale and modify images before they are uploaded to a webserver.
    ImageMagick is called from our Objectiv-C app via
    command line.
    is there a way to this in Java?
    Regards
    Eckbert

    So, ur question is not developing a Java application that
    will do the 'image conversion'; but, your message
    conveys that u want to know how to invoke a Java program built by 'imagemagick' that takes command line arguments?
    Am I right?
    If that's the case, u must look into the documentation
    given along with the download'ed piece of software
    for identifying the 'starting point of the program'. i.e., the
    class that contains the 'main' method! And after you
    identify that class [Eg. ImageMagickStart] then you'll
    have to invoke as follows:
    [you must have Java installed in ur system!]
    c:>java ImageMagickStart
    If the program was written intelligently it must print all
    the command-line arguments required by the above
    program by executing the above command, and from that
    you can identify!
    -RK

  • Satellite X200 with Windowa 7 became slow with JAva 6 update 17

    After installing Windows 7 on my Satellite X200 I made the upgrade of Java from update 10 to update 17. The computer became very slow when ther a Java window opened in IE8. I uninstalled update 17 and installed update 10 again at no avail. Please help!

    I agree with you and will try to get an answer on a Java forum. I tried a recovery to an earlier date but the recovery failed, probably because I had already unninstalled the original java update 10. The same happened even after I reinstalled update 10 (which, by the way, is not shown on the list of programs of the Control Pane remove programs list.

  • How to retain new line characters when using Node.getNodeValue()

    Hi,
    I have xml as shown bellow
    *<DETAILS>*
    this is line one
    this is line two
    thi is line three
    *</DETAILS>*
    when I parse this using dom( Node.getNodeValue() ), the value I am getting is as shown bellow
    this is line onethis is line twothis is line three
    but I wanted as is I have in my xml i.e,
    this is line one
    this is line two
    this is line three
    ( to show that as is in HTML page)
    can some body help me ??
    Thanks in advance .

    Hi,
    You could try this:
    replace(your_data, chr(10), '')

  • Extra new line characters

    The HTMLEditor kit inserts extra newline characters when there is a space in the line and the line is greater than 80 chars? Can anyone tell me how to get rid of these extra newlines or how to set an unlimited or hugh line length as would be seen in HTML?
    Thanks in advance!!

    Hi
    I've the same problem, does anyone get a solution to this?
    Thanks for your help!

Maybe you are looking for