Remove last newline character

How can I remove the newline character only from the very end
of a string? (Note there are several newline characters within the
string). Thanks!

How long is the string and roughly how many newline
characters are there? One way, although kinda funky, would be to
convert the newline-delimited list to an array, and then convert it
back. See below.

Similar Messages

  • How to remove the newline character at the start in the attachment ?

    Hi All,
    I have been trying to attach a .dat file generated at an external source and send it as an attachment by mail using UTL_SMTP, all things are working but the .dat file which comes attached in mail contains a newline character i.e. chr(10) at the start line and the contents of the file are written from second line onwards. Below is some part of the code which deals with read/write of attachment of mail to be sent.
    Can anyone help me on this, is something to be changed in this code??
    UTL_SMTP.write_data(c,
    'Subject' || ': ' || P_SUBJECT || UTL_TCP.crlf);
    UTL_SMTP.write_data(c,
    'MIME-Version: 1.0' || UTL_TCP.crlf || -- Use MIME mail standard
    'Content-Type: multipart/mixed;' || UTL_TCP.crlf ||
    ' boundary="-----SECBOUND"' || UTL_TCP.crlf ||
    UTL_TCP.crlf);
    UTL_SMTP.write_data(c,
    '-------SECBOUND' || UTL_TCP.crlf ||
    'Content-Type: text/plain;' || UTL_TCP.crlf ||
    'Content-Transfer_Encoding: 7bit' || UTL_TCP.crlf ||
    UTL_TCP.crlf);
    UTL_SMTP.write_data(c, UTL_TCP.crlf || l_text);
    UTL_SMTP.write_data(c, UTL_TCP.crlf);
    UTL_SMTP.write_data(c, UTL_TCP.crlf);
    UTL_SMTP.write_data(c,
    '-------SECBOUND' || UTL_TCP.crlf ||
    'Content-Type: text/plain;' || UTL_TCP.crlf ||
    ' name="/inetpub/wwwroot/Novation_Merge/FS_Extract.dat"' ||
    UTL_TCP.crlf ||
    'Content-Transfer_Encoding: 8bit' || UTL_TCP.crlf ||
    'Content-Disposition: attachment;' ||UTL_TCP.crlf || ' filename="' || p_description ||
    TO_CHAR(SYSDATE, 'DD-MON-YYYY') || '.dat"' ||
    UTL_TCP.crlf || UTL_TCP.crlf ||UTL_TCP.crlf);
    BEGIN
    l_filehandle := UTL_FILE.fopen('c:\temp',
    'FS_Extract.dat',
    'r',
    32767);
    LOOP
    UTL_FILE.GET_LINE(l_filehandle, l_buffer, 32767);
    UTL_SMTP.write_data(c, l_buffer || UTL_TCP.crlf);
    END LOOP;
    EXCEPTION
    WHEN OTHERS THEN
    NULL;
    END;
    UTL_FILE.fclose(l_filehandle);
    UTL_SMTP.write_data(c, '-------SECBOUND--');
    UTL_SMTP.close_data(c);
    UTL_SMTP.quit(c);
    EXCEPTION
    WHEN UTL_SMTP.transient_error OR UTL_SMTP.permanent_error THEN
    BEGIN
    UTL_SMTP.quit(c);
    EXCEPTION
    WHEN UTL_SMTP.transient_error OR UTL_SMTP.permanent_error THEN
    NULL;
    -- When the SMTP server is down or unavailable, we don't have
    -- a connection to the server. The quit call will raise an
    -- exception that we can ignore.
    END;
    RAISE_APPLICATION_ERROR(-20000,
    'Failed to send mail due to the following error: ' ||
    SQLERRM);
    END;
    Thanks,
    -Amol

    As I recall, a single blank line serves as separator between Mime Header and Mime Body.
    This code..
    UTL_SMTP.write_data(c,
      '-------SECBOUND' || UTL_TCP.crlf ||
      'Content-Type: text/plain;' || UTL_TCP.crlf ||
      ' name="/inetpub/wwwroot/Novation_Merge/FS_Extract.dat"' ||
      UTL_TCP.crlf ||
      'Content-Transfer_Encoding: 8bit' || UTL_TCP.crlf ||
      'Content-Disposition: attachment;' ||UTL_TCP.crlf || ' filename="' || p_description ||
      TO_CHAR(SYSDATE, 'DD-MON-YYYY') || '.dat"' ||
      UTL_TCP.crlf || UTL_TCP.crlf ||UTL_TCP.crlf);  ..generates 2 blank lines after the Mime Header.
    Remove the last CRLF and see if that does the trick.

  • How to remove a newline character from a column

    hi all...
    i have a column in a table in which some of the datas contain a newline character at their last.
    i need to remove those newline characters.
    for example.... a data is
    'abcd
    (notice the end of the quotation).....i need to get the data as...'abcd'
    plss help me...
    thanks in advance..

    thanks for ur reply...
    i got your point..but here what you have done is....u have inserted a particular character set in between 'abcd' and 'xyz' and afetr that just replaced those character set by null....
    but in my case the problem is a bit different...
    the datas are already present and what i have to do is to remove the newline spaces from the end of the datas.
    select replace(column_name,'<what shall i put here>',null) from table_name;
    in your example...that is 'chr(10)'...but in my case its a newline character....

  • Best way to remove last line-feed in text file

    What is the best way to remove last line-feed in text file? (so that the last line of text is the last line, not a line-feed). The best I can come up with is: echo -n "$(cat file.txt)" > newfile.txt
    (as echo -n will remove all trailing newline characters)

    What is the best way to remove last line-feed in text file? (so that the last line of text is the last line, not a line-feed). The best I can come up with is: echo -n "$(cat file.txt)" > newfile.txt
    (as echo -n will remove all trailing newline characters)
    According to my experiments, you have removed all line terminators from the file, and replaced those between lines with a space.
    That is to say, you have turned a multi-line file into one long line with no line terminator.
    If that is what you want, and your files are not very big, then your echo statement might be all you need.
    If you need to deal with larger files, you could try using the 'tr' command, and something like
    tr '
    ' ' ' <file.txt >newfile.txt
    The only problem with this is, it will most likely give you a trailing space, as the last newline is going to be converted to a space. If that is not acceptable, then something else will have to be arranged.
    However, if you really want to maintain a multi-line file, but remove just the very last line terminator, that gets a bit more complicated. This might work for you:
    perl -ne '
    chomp;
    print "
    " if $n++ != 0;
    print;
    ' file.txt >newfile.txt
    You can use cat -e to see which lines have newlines, and you should see that the last line does not have a newline, but all the others still do.
    I guess if you really did mean to remove all newline characters and replace them with a space, except for the last line, then a modification of the above perl script would do that:
    perl -ne '
    chomp;
    print " " if $n++ != 0;
    print;
    ' file.txt >newfile.txt
    Am I even close to understanding what you are asking for?

  • External table and newline character

    I have an external table which is just a csv file, records delimited by newline and fields terminated by ','. However, the last column has a newline character appended to it. Is there an option in the external table syntax which will trim this?

    Try setting 'REJECT ROWS WITH ALL NULL FIELDS'
    http://download-west.oracle.com/docs/cd/B10501_01/server.920/a96652/ch12.htm#1011062

  • SQL*Loader sqlldr removes zeros from character field

    Hello,
    I am using SQL*Loader to load an Oracle table, and am having a problem. One of the fields is defined as VARCHAR2 and contains comments entered by a user. There may be numbers or dollar amounts included in this text. When I execute the sqlldr script below, the result is that all of the zeros on the text field disappear. There is a translate function invoked for this field (bolded statement) in an attempt to remove imbedded newlines from the text. Wherever there was a zero in the original text, it ends up being removed after I run this script. Can anyone suggest why this is occurring, and how to prevent it? Can it be related to the translate function?
    Thanks for your help!
    OPTIONS (READSIZE=20971520, BINDSIZE=20971520, ROWS=20000)
    LOAD DATA
    INFILE 'R24.REGION.ERL.N1E104' "str X'5E5E220A'"
    BADFILE 'LOGS/N1E104_BUT_RS_ASSGN_TXT_BADDATA.TXT'
    DISCARDFILE 'LOGS/N1E104_BUT_RS_ASSGN_TXT_DISCARDDATA.TXT'
    REPLACE
    INTO TABLE TESTM8.CONV_BUT_RS_ASSGN_TXT
    FIELDS TERMINATED BY '~' OPTIONALLY ENCLOSED BY '"'
    TRAILING NULLCOLS
    RST_RS_EXT_TXT_OID DECIMAL EXTERNAL,
    RST_RS_ASSGN_OID DECIMAL EXTERNAL NULLIF RST_RS_ASSGN_OID = 'NULL',
    RST_TXT_SEQ_NBR INTEGER EXTERNAL,
    RST_RS_COMM_OID DECIMAL EXTERNAL,
    RST_DIF_ASSGN_OID DECIMAL EXTERNAL NULLIF RST_DIF_ASSGN_OID = 'NULL',
    RST_EXTENDED_TXT "SUBSTR(TRANSLATE(:RST_EXTENDED_TXT, '#0x0A', '#'), 1, 248)"
    --------------------------------------------

    Never mind, found my mistake. In the TRANSLATE function, I had assumed that the 0x0A would be interpreted as a single hex value. Instead, it is interpreted literally as the character '0', the character 'x', the character 'A', etc. The result is that the transformed text had no '0', 'x', or 'A' characters, which is exactly what I inadvertently told it to do. I changed it to the following, which works better ;-)
    RST_EXTENDED_TXT "SUBSTR(TRANSLATE(:RST_EXTENDED_TXT, '#'||CHR(10), '#'), 1, 250)"

  • Getting the newLine character when deleting a line...

    I have a JTextArea that has a custom DocumentListener added. What I want is to be notified when the user hits enter for a new line and be notified when the user removes a line. Getting the newLine when the user hits enter is easy enough, however the reverse is not true. Whenever backspace is pressed it gets the same removeLine character, which is not what I want, because a backspace is not a removeLine( or newLine) character. Here is my code so far...
              public void insertUpdate(DocumentEvent e){
                   Document d = e.getDocument();
                   try {
                        String s = d.getText(e.getOffset(), e.getLength());
                        System.out.println("got a line");
                   } catch (BadLocationException e2) {
                        e2.printStackTrace();
              public void removeUpdate(DocumentEvent e){
                   Document d = e.getDocument();
                   try {
                        String s = d.getText(e.getOffset(), e.getLength());
                        if(s.equals("\n"))
                             System.out.println("removed a line");
                   } catch (BadLocationException e2) {
                        e2.printStackTrace();
              };It's in the removeUpdate that my code is flawed. Can anyone stear me in the right direction?

    What for?By definition when you have a problem, you don't know what the problem or solution is. So you post a SSCCE showing what you've attempted so far so that we can see the problem you are describing.
    Since you also don't know how to ask a very clear question. The SSCCE help in describing the problem. Maybe it won't help in this case, but you don't know that before hand. So you get in the habbit of always posting a SSCCE.
    You talk about removing a line, but I don't know what that means. What happens if you data in a text area like:
    123
    456
    789
    To me removing a line means removing "123\n" to that the entire line is removed from the file. Or what happens if you select 3 and 7 with the mouse and then use the "Delete" key? Did you remove 1 line or 2 lines. Are you trying to count the number of "\n" characters that have been removed. Or do you only care about the backspace key because that was a concious decision or did you just not think about all the other possibilities of how text can be removed from a Document?
    So as you can see you question is not a simple and straight forward as you thought. Without a SSCCE to clarify exactly what you are doing we can only provide half an answer.
    You can find the answer by reading the Swing tutorial. Maybe the section on Key Bindings, if you just want to know when a certain key was pressed. Or maybe the section on a DocumentFilter if you want to know what text has actually been added or removed from the Document (before it happens).

  • Lyrics on ipod touch: newline character?

    Is there a newline character for lyrics to allow me to separate stanzas when displayed on ipod touch?
    Right now all the lines (and thus stanzas) are running together.

    Step by step:
    In iTunes, have you added the lyrics to each individual song and in the lyrics tab of the song?
    If you use Sync to manage your iPod, have you then Synced your iPod after adding the lyrics?
    If you manually mange the iPod, you need to remove the album from the iPod and then add it back again (with the lyrics)
    If you still have no luck, then if you use Sync, try typing anything into the lyrics field of any song. Then after a Sync with the iPod, check that song. When you can see the scrubber bar (with the time), you should be able to see the text you typed.
    If you manually manage the iPod, remove one song from the iPod, add some text to that song and then add it back onto the iPod and play it. Can you see the lyrics now?
    If none of that works, perhaps the iPod need a Reset or a Restore.

  • How to escape newline character(nl) in file content conversion parameter?

    Hi Experts,
    How to escape newline character(nl) in file content conversion parameter?
    For example:
    field1field2field3
    field4field5field6
    Means Item is splitted in two lines.
    I want to SKIP new line character
    and to collect all SIX fields.
    What will be the file content conversion parameter?
    Thanks in Advance..........

    Hi,
    as far as i know there is nothing in the standard. But the question is why dont you combine at mapping the fields into only structure?
    Regards,
    Udo

  • File format for newline character

    Hi there, I have a scenario to do. From IDOC to flat file. I receive a number of idocs and must convert them into a flat file. Each idoc must start on a new line. Each line represents a new record. I have done this and it works fine. But now the system reading the flat file is having trouble with the newline character. Im using ABAP mapping to create the flat file and the newline characters I tried are
    l_crlf(2) VALUE %_cr_lf
    l_crlf(1) VALUE %_NEWLINE
    Lest say I open the flatfile in MS Word and do a character count it shows as 100 char's but on there system it shows as 101. It has something to do with the file format..
    Does anyone know how to fix this?
    Thanx,
    Jan

    It turnes out that their file encoding was not the same as ours so I just changes the file type brom binary to text and set the encoding to UTF-8
    Thanx,
    Jan

  • Newline character in a String

    Hi,
    How can i introduce a newline character while displaying a string using string functions in a report..
    My requirement is, i need to replace a particular character with a newline character in a string using replace function
    Can anyone help me
    Thanks in advance..

    Hi,
    Try this,
    REPLACE(Table.ColumnName, 'StringOrCharacterToReplace', '[br]')
    *replace [ and ] with < and > in br tag. Change the data format of the column to HTML
    Rgds,
    Dpka

  • Is is standard for JSP to output every newline character it sees?

    I've encountered a very annoying problem using JSP. It seems JSPC outputs every newline character it sees in the JSP page -- even if it is after a JSP comment or JSP directive. Look at the sample JSP at the bottom: it will output 4 blank lines (3 from comments + 1 from directive) before it prints "JSP Body Line 1". Granted, this is not a big problem if the content is HTML and will be viewed in a browser. However, my content has to be plain text because the client in my case is not always a browser.
    I've tested this on both JRun and TomCat. Same results. I don't understand why is this, because intuitively the JSP designer would not have meant to output those blank lines, right? I'm wondering if this is really an "official" behavior prescribed by the JSP standard, or just an oversight in JRun and TomCat? Could any expert help me verify this in JSP standard (by the way, which one is the official document that spells out the JSPC implementation?) or anyone help me test it in other App Server (e.g. WebLogic, WebSphere, etc.) which I don't have access to? Your help is greatly appreciated!
    ======= Sample JSP code ========
    <%-- JSP Comment Line 1 --%>
    <%-- JSP Comment Line 2 --%>
    <%-- JSP Comment Line 3 --%>
    <@ page contentType="text/plain" %>
    JSP Body Line 1
    JSP Body Line 2
    ...

    The truth is, newlines (as far as HTML or most XML is concerned) are just any old kind of whitespace. An extra line or two isn't a major problem, the only time this will really cripple you is if you want to insert scriptlets above the <?xml...> line.

  • NewLine Character in the String received from Interactive Adobe Form

    Hello Experts,
    Following is the issue we have with interactive Adobe Form
    We have a text area within the form. User enters the text in multiple lines in this text area.
    We are calling a backend function module designed in SE37 that accepts and process the data from the adobe form.  We are also processing the string data user enters in the text area.
    When we receive the string from the form, the newline character within the string is displayed as '#' in the debugger. We tried splitting this string using cl_abap_char_utilities=>newline and cl_abap_char_utilities=>cr_lf  but NO luck. Though in the debugger we see cl_abap_char_utilities=>newline  as '#'  in the debugger and also '#' is present within the string, for some reason when string is processed to find cl_abap_char_utilities=>newline, we can find/locate it.
    Because ABAP code is not able to identify the newline character within the string received from Adobe form, we are not able to maintain the formatting of the string as it was entered in the form.
    Any help to resolve this issue is appreciated.
    Thanks in Advance.
    Regards,
    Bhushan

    Hi Bhushan,
    I was going through your issue, and I feel this is something you can do with scripting. Basically you should read whole string and find the new line character and replace with a space or comma, as per your requirment.
    Do like following:
    In the exit event of the field select java script and write following code:
    var strng = this.rawValue;
    strng.replace(/\n/g, " ");
    above im reaplcing new line with a space.
    I think it should work I have not tested it. Pls update if you test it .
    Regards,
    Ravi.D

  • Remove unicode control character

    hey, so i've asked this around a few places and recieved no answers, but the arch community seems like a bunch of smart people and i've recently switched over from ubuntu.
    is there a way to remove input methods and unicode control characters from the context (right-click) menu? i've searched and searched, but i've had no luck with this.
    there's a way to remove it in gnome with gconf, but i've tried that, and no luck.
    i'm using openbox, and i think i found something about my gtkrc file along these lines
    gtk-show-input-method-menu =
    gtk-show-unicode-menu =
    both are "gboolean" which i don't know what it is, or if this is even what i want.
    any help would be appreciated, as i never use these menus.

    U+2415, SYMBOL FOR NEGATIVE ACKNOWLEDGE is not a control character. It is a normal symbol character, which is a substitute display character used when the control character U+0015 NEGATIVE ACKNOWLEDGE is to be displayed instead of being interpreted.
    You need to refine your question.
    In general, you can remove any particular character or characters from a string using the SQL functions TRANSLATE or REPLACE. You can use CHR or UNISTR to encode characters that you cannot enter from a keyboard. You can use REGEXP_REPLACE with POSIX character classes to remove broader ranges of characters.
    -- Sergiusz

  • Inserting newline character  in header in messageformat class

    i've to print 5 lines in header.i've created header using messageformat class.But the newline character not working.(paper size:width=4in)please help.

    Thanx for ur reply.
    i've to print a jtable.i couldn't change font size and also no. of lines for headers.i want the font size same as that of the footer.
    here is my code
    jtable.print(printmode,headerformat,footerformat,null, false, null)

Maybe you are looking for

  • Application builder switiches to Chinese language

    I'm using LabVIEW 2010 over Windows 7 Professinal. Sometimes when building an executable all the text on the created executable standalone application changes to Chinese. After a restart of the computer and executing the application builder I get the

  • Signed applets in 1.4.1: non-trust ignored: severe security problem?

    Hello all, I am signing applets with a developer certificate. Until know everything worked fine with Plugin 1.3.1. Know I changed to Plugin 1.4.1 and encountered a strange behaviour: When I open the HTML page with a browser (tried IE 5.5 and Mozilla

  • New hard drive shows in Bios and device manager but not in windows explorer in windows 7

    I have added a new sata 500gig hard drive and it is recognised in the bios, but is not recognised by windows explorer, though the disk is showing in device manager as a hard drive . I have followed the example on the forum by going to computer manage

  • Batch has already been posted in stock **very urgent**

    Dear all, My user has created a delivery for excess quantities. He had to deliver only 4 where he has done the PGI for 24. I thought I would reverse it with transaction VL09, but when I click on reverse this error "Batch has already been posted in st

  • Reformat my iPod from Mac to IBM compatible?

    Can this be done on a IBM machine? I just sold my iPod and it's Mac formated. The buyer wrote me this: "My concered is that it will not be IBM compatable. You said so but that doesn't mean that it will. However I have completed checkout but I will be