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++;
}

Similar Messages

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

  • 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>".

  • 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

  • Adding New Line character to String

    Hi,
    I want to add a new line while concatenating strings.
    I am getting some string objects and put them together. while concatenating them i want new string to be displayed in new line.
    The purpose of this is i am displaying this bunch of strings on a mouse over finction using javascript. Hence i want the different values to be displayed on a new line.
    Any help is appreciated.

    You normally use \r\n or System.getProperty("line.separator") to get a newline in Java.
    But since you're talking about Javascript, the whole question makes really no sense here at a Java forum. Don't you just mean a linebreak in HTML? If so, it is just
    . If not, please elaborate or look for a Javascript forum. There are ones at webdeveloper.com and dynamicdrive.com.

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

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

  • Having problems PrintWriter and new lines in a string

    I apologise if this topic is in the wrong place, but this is my first time asking on these forums.
    At the moment I have a window with an output text area which I want to store the contents of into a file. I use getText() to store the contents to a string, and then write the string to a file using a BufferedWriter. the code is as follows:
    BufferedWriter out = new BufferedWriter(new FileWriter(file));
    String contents = output.getText();
    out.write(contents);
    out.close();The file-name is specified by a FileChooser. All of this works fine, and the text is actually written to the file ok, except that there are no line breaks in it (it's just one continual line of text). I have tried the same process using a string containing "test\ntest" to see if it is just a problem getting the contents of the text area, however it still gives me the same problem.
    Any help on this would be much appreciated.

    Take a look at PrintWriter.
    o See if you can wrap it around a BufferedWriter. (It
    may alrady BE one.)
    o Use it's .println(...) method.That'll still make it appear as one line though. The one-and-only "line" will have the correct platform-specific line terminator (\r\n I suppose), but the string he is writing has embedded \n characters in it, which he is expecting to show up as new lines.
    The OP needs to realize that there really aren't any such thing as "lines". It's all up to the software rendering the text to treat "newline" characters/sequences special. If you were to open that file with a different tool (not Notepad, which only recognizes \r\n as newline sequences), it may display it the way you are expecting.
    Or, you'll have to parse the text and convert it to the proper newline sequences before you write it to the file.

  • Need to print new line when "," in string

    Hi,
    I have a string having value 12,221,23,67...
    I need to print a new line after ", "
    i;e 12
    221
    23
    67....
    Please suggest.
    Thanks,
    Ajit

    Hi Team ,
    its done.
    I have used chr 13, chr10 and it print new lines for me
    v_serial_num:=v_serial_num||','||CHR(13) || CHR(10)||rec.SERIAL_NUMBER;
    Thanks,
    Ajit

  • What  new line character in string is needed to show new line

    If i need to show java string in a html text area with new lines(that is 2 -3 lines of text ) what new line character i need to add.
    I tried \n and /n but these are not working fine. Can anyone help me.

    If i need to show java string in a html text area
    with new lines(that is 2 -3 lines of text ) what new
    line character i need to add.
    I tried \n and /n but these are not working fine. Can
    anyone help me.HTML ignores line breaks. You will need to use markup (<br>) to force a new line.

  • How to make new-line when printing strings?

    Please help me with code . I can't able to print the string in new line
    Anil

    ... the same question as your other post:
    Printing the string

  • Replace new line from xml string

    hi,
    I am getting an input string as given below
    <div class="titleBar">               
              <h1>sssPRIVACY POLICY AND YOUR CALIFORNIA PRIVACY RIGHTS</h1>               
         </div>
         <div class="txtPod"> And I want to replace all the blank lines and the output should be like
    <div class="titleBar">
              <h1>sssPRIVACY POLICY AND YOUR CALIFORNIA PRIVACY RIGHTS</h1>
         </div>
         <div class="txtPod"> I tried replaceAll("\n",""), but that doesn't seem to work.
    Can somebody help me on this

    str = str.replaceAll("(?m)^[ \t]*\r?\n", "");

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

  • 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), '')

  • New line in String

    Hi,
    how can I get a "new line" in a string?
    \n
    and
    <br />
    doesn`t work.
    I tried it with a LANGUAGEINDEPENDENT_SHORT_NAME and a lot of different UI controls(StaticText, InputField etc).
    Regards,
    Andreas

    Alle Mehrzeiligen Datentypen sind, so glaube ich jedenfalls, inkompatibel zu ABSL.
    Webservice unterstützt z.B. Mehrzeiligkeit sofern ein enspr. Typ im BO dafür verwendet wird! z.B. Text
    Um in ABSL Mehrzeiligkeit zu erhalten würde ich mit Ruby ein Dummy Feld mit einen "Return" füllen.
    z.B. $controller.StringUtils.AsciiToChar(int) -> habe ich aber noch nicht getestet.
    Danach könnten die Felder evtl über
    this.multifield = "my 1. text" + this.dummy + "my 2. text";
    gefüllt werden.
    Gruß Kay

Maybe you are looking for

  • Fixit cannnot open PDF files

    I cannot open PDF files in Firefox - I get a grey screen stating 'This plugin is vulnerable and should be updated'. I go to updates for Fixit and the link takes me to things I just do not understand. I have been using Foxit Reader and it is my defaul

  • Referencing a MovieClip on stage through XML

    Hello. I have a swf with several MovieClip instances on the stage at authoring time. For example, say I have mBuilding that contains mFloor, that in turn contains mAppartment. I have an xml file that contains data so the swf knows what to do with the

  • Any way to Cut In-to-Out?

    Is there any way in CS6 to mark an In and Out point, then use Cut or Copy to lift the marked section (using whatever tracks are "on") for Pasting elsewhere? Or is there some other way to accomplish this, without having to "add edits" ("razoring") the

  • Syntax Error when trying to do Immediate sync to our LDAP

    Lately, we have been getting an error when ever we try to force an LDAP sync. Users are able to login via our LDAP connection to teaming... but I believe that we are no longer able to import new users. Below is a snippit from our catalina.out file wh

  • Install crashed out??

    I was trying tp update my Blue G3 from 10.2.8 to 10.3. When the install disc restarted my computer all that came up was a gray screen. Now I can't get the computer to boot up at all, not from the disc and not from the internal drive. I have tried reb