Length of a String with new line

Hello
I have a Form that allows user to fill in. In that form, I have an address field (textarea).
Now I want to know the length of this address. I uses
String size = addressField.length();
The size is correct if I have only one line in the address. But if I enter an adress with multi-line, the size is much more than what I count (by hand) even I add one value for each line.
For example, if address "Wellington" has one line as:
Wellington
It can be seen that the size is: 10
But if I enter this in multi lines:
W
e
ll
ing
ton
It can be seen that, by counting, the size is 14 (10+4=14)
However, I get the value of addressField.length() is 18
How I should get value for only 14
Many thanks
shoa

You realize, of course, that you cannot use Javascript to execute Java code like that, right? Java runs on the server, Javascript runs in the browser, and there is no connection whatsoever between the 2. At best, you can use Java to write Javascript code into a page. But calling count() in Javascript will not execute that Java/JSTL code.

Similar Messages

  • String with new lines in sql and java

    i'm using mysql as my database. In one of the columns (nameCol) stores a string, 'hello, my name is earl'
    In my java app i want to display this in a text area so that it looks like:
    hello,
    my name is earl
    in mysql i did: INSERT INTO Table (......,nameCol) VALUES(.....,'hello,\nmy name is earl'); This inserted the data into the database in the format i wanted (as above) but when i printed it in my app it came out like hello, my name is earl.
    My sample code:
    //some code above to set a parameter for a select statement to get a unique row
    //get data from the nameCol field  ..this all works fine
    String nameC = (String)nameDataProvider.getValue("Table.nameCol");
    //set the text area
    myTextArea.setText(nameC);Anyone know how i can get it to display in the format at the top?

    Well, one reason for that is that \n not necessarily leads to a line wrap. Wrap chars are system dependant. Try using System.getProperty("line.separator") instead.

  • String with multiple lines

    hi
    i have a string with multiple lines inside it eg.
    hello this is
    my string with
    mutiple lines inside it
    how could i get it to print out line by line
    iv used "\n" so it detects the new lines but it doesnt seem to work
    this is my following code that doesnt seem to detect the newline
    if(multiString.equals("\n")){
    }

    nicchick wrote:
    i have a string with multiple lines inside it eg.
    hello this is
    my string with
    mutiple lines inside itWhere do you have this String? In a file? in a JTextArea of a Swing GUI? Details are important.
    if(multiString.equals("\n")){But the whole string isn't an "\n" so this won't do. Again, much will depend on the current state of the String. You may need to split it based on the current line separator.

  • Splitting a string on new lines...

    If I want to split string on whitespaces, I do:
    StringTokenizer st = new StringTokenizer(a, " ");If I want to split a string on new lines, (I think the ascii values are "13", "10") how can I do it?
    Thanks a lot!

    does "\n" represents both chr(13) and chr(10) ?No, it does not.
    KajI solved with "\r\n"Did you read the other replies? They are correct when they say that you shouldn't use StringTokenizer.
    Kaj

  • Problem with new line

    Hi,
    I'm trying to write a note for a contact.I have written following code
    contact.addString(Contact.NOTE, contact.ATTR_NONE, "bla bla bla");it works, but when i write
    contact.addString(Contact.NOTE, contact.ATTR_NONE, "bla \n bla \n bla");it doesn't work. What's wrong with newline
    Can anybody help me to fix it.??

    I'm still working on emulator.
    If I write
    contact.addString(Contact.NOTE, contact.ATTR_NONE, "bla \n bla \n bla");actually it's still working but the "\n" is ignored. The output is
    >>bla  bla  blanot
    >>bla
    bla
    bla but if I write (without space after new line)
    contact.addString(Contact.NOTE, contact.ATTR_NONE, "bla \nbla \nbla");it's not working and doesn't have any output. Is "\n" really not supported or it's a bug .??
    Thx

  • Problem with new lines

    I have defined a form in Dreamweaver  to be used in conjuction with my SQL database (I am using the PHP/SQL).  One of the fileds in my form is of type TEXT (as opposed to VAR CHAR). Now, eventhough the text I am entering for that TEXT field has a number of paragraphs, when I read back the TEXT  field from the database (via sql SELECT),  the data for the TEXT field comes out continuously without paragraps. I don't understand why the paragraph or newline markings are not working when TEXT type data is retrieved from the database.  Can someone help me please.  Thanks!

    This is because HTML ignores new lines. The solution is to use the PHP function nl2br(). Depending on which version of Dreamweaver you're using, you can apply this function through the Bindings panel like this:
    This is certainly available in CS4, and maybe in CS3 too; but not earlier versions.
    If you're using an earlier version of PHP, wrap the dynamic text in nl2br() like this:
    <?php echo nl2br($row_recordsetName['fieldName']); ?>

  • OdiFileAppend tool issue with new line character?

    Hello ODI experts,
    I am using OdiFileAppend tool in a package to concatenate multiple files with same structure to a new file. ODI is installed in windows and also files exists in Windows only.
    OdiFileAppend "-FILE=C:\ODI_WORK\FILE_LOAD_DIR\PROCESS_DIR\*.*" "-TOFILE=C:\ODI_WORK\FILE_LOAD_DIR\PROCESS_DIR\CONCAT_FILE.txt" "-CASESENS=NO" "-OVERWRITE=YES" "-HEADER=1" "-KEEP_FIRST_HEADER=YES"
    First File:
    CST_ID,CST_CODE,CST_NAME,CST_STATUS,CST_ID_PAC,CST_ID_CHO
    -3,TWO,TXTFILE,A,864,
    second File:
    CST_ID,CST_CODE,CST_NAME,CST_STATUS,CST_ID_PAC,CST_ID_CHO
    -2,ONE,TXTFILE,A,864,
    output file by using OdiFileAppend tool is as below with two lines:
    CST_ID,CST_CODE,CST_NAME,CST_STATUS,CST_ID_PAC,CST_ID_CHO
    -2,ONE,TXTFILE,A,864,\-3,TWO,TXTFILE,A,864,\
    How can we modify the tool to append records in a new line?
    Thanks

    Hi Murali ,
    You are facing a Bug .
    The Oracle Data Integrator (ODI) defect is referenced as <<Bug 6518478>> <ODIFILEAPPEND DOES NOT WORK AS EXPECTED>.
    When Oracle Data Integrator (ODI) OdiFileAppend/SnpsFileAppend tool is used with -HEADER parameter set to 1 or higher, the resulting file is incorrect and a backslash ("\") character is automatically generated between the appended files.
    This Bug is fixed in ODI 11gR1
    If the generated file is to be used as Source Datastore in an Oracle Data Integrator (ODI) Integration Interface, to work around the behavior:
    1. Appending the files using the OdiFileAppend/SnpsFileAppend tool without the -HEADER parameter (or use "-HEADER=0").
    2. Then, in your Integration Interface, apply a Filter to the corresponding Datastore in order to remove the unused headers.
    Thanks,
    Sutirtha

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

  • Updating existing PO with new line item

    Hi
    We are in ECS scenarion. I want to add a new line item to the already existing Po which was transferred to the R/3 system successfylly. I have user pd_po_update and pd_po_save . In pd_po_update I am getting changes = "X"  but in es_guid it seems i am getting the old guid . after executing the program when I go back a message popsup saying "update was terminated".
    Please let me know what should  i do in order to add a new line item to the PO.
    thanks
    sankar

    Hi Sankar,
    You must add a COMMIT WORK after having passed the BBP_PD_PO_SAVE.
    Regards,
    Laurent.
    Don't forget points if helpfull.

  • Regarding problem with new line feed for DME file generation

    Hello Experts,
    I m facing a problem in the DME file generation.
    we want each record in the DME file should be in new line. for that we have add the new line feed character in the each row end. So in the SAP output it looks ok, But if we download that file the carriage return field is coming in the end of every row.
    can any one tell how to solve this issue.
    Please refer the below line code which i m using for new line
    DATA: GM_newline TYPE c VALUE cl_abap_char_utilities=>CR_LF
    You reply is valuable..
    Thanks,
    Suresh

    DATA: GM_newline TYPE c VALUE cl_abap_char_utilities=>newline.

  • I have moved my itunes to a  new computer and now my ipod will lnot sync with new line up

    i have moved mu itunes to a new computer and my ipod will not sync with new music.

    If you are using automatic syncing, you may need to set up the iPod's Music tab in iTunes.
    Select the iPod in iTunes.  There is a row of "tabs" (starting with Summary).  Select Music there.  This is the Music tab, where you tell iTunes how to sync the iPod with songs.  Sync Music is checkmarked for automatic syncing.
    If your entire iTunes music library can fit on the nano, you can choose to sync Entire music library.  Otherwise, you can choose to sync Selected playlists, artists, albums, and genres.  Then, create your selection of songs below.  For example, if you want to keep it simple, create a new playlist in iTunes.  Put ALL songs you want on the iPod on that playlist, including songs from the newly added music.  Back on the Music tab, find and checkmark that new playlist under Playlists.
    When you click Apply, your selection of songs on the Music tab syncs to the iPod, replacing its current content.  Going forward, any changes that are related to the Music tab settings sync automatically when you connect the iPod, or when you click Sync.  So, if there is a playlist with your "iPod songs," you can just update that playlist (add and remove songs) whenever you want; iTunes updates the iPod with the same changes at the next opportunity.

  • How to make a String with a line break?

    I want to insert a line break into a strhing...i am trying to do this using a Stringbuffer the following way:
    name = new StringBuffer().append("something").append('\n').append("else").toString();
    but it doesnt' seem to be working.
    any suggestions??
    Andrew

    that was just an example for testing purposes...if
    you read my posts.....
    i said:
    "i am passing a string to my corel template creator
    which is made in java and creates a template in Corel
    Draw.
    but when the string is being passed to the template
    creator i want it to be able to distinguish whether
    the string is supposed to be 2 lines or 1."
    i see zero correlation between that and HTML
    AndrewYour posts thus far strongly suggest that this text will utimately be HTML that will be rendered by a browser. I don't know what this Corel template is, but based on the other stuff you've said, I assumed it was some sort of HTML page template.
    If the text will ultimately be HTML that is rendered by a web browser, then the Corel stuff is irrelevant (unless the Corel template is a JSP or other dynamic page generator that lets you specify by some other means where to put line breaks, in which case you need to look at Croel's docs), and you need to insert <br> or <p> or use <pre> tags.
    If the Corel template is some sort of Java widget and you won't be rendering HTML with a web browser, then look at the docs for the Corel template, or contact Corel tech support.

  • REALLY need help with new lines

    Ok,
    I have been thinking for hours and cannot find the solution to my problem.
    My issue is that when I write text to a file:
    ...Initiate bufferedwriter
    bw.write("CODE");
    bw.write(System.getProperty("line.separator"));
    bw.write("CODE2");...it comes out normal, but when I read it:
    ..Initiate bufferedreader
    String st=br.readLine();
    String st2=br.readLine();st comes out as CODECODE2
    st2 comes out as null
    WHAT AM I DOING WRONG???????????????????

    EXACT snippets from the program:
    String[] fin=st.split("\n");
    for(int i=0;i<fin.length;i++) {
                    fos.write(fin);
    fos.write(System.getProperty("line.separator"));
    fos.flush();
    fos.close();
    fw.close();
    (st is text to write)String st=br.readLine();
    while(true) {
    String st2=br.readLine();
    if(st2==null) {
    break;
    else{st=st+st2+System.getProperty("line.separator");}
    br.close();                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How can i get the length of a string with Simplified Chinese?

    when i use eventwriter to add content to a xmldocument,there are some chinese simplified string in it,i use String.length() for the length ,but it is not correct~how can i get the right length for eventwriter?

    Below is a simple patch for this problem. Using this patch you need to pass 0 as the length argument for any XmlEventWriter interfaces that take a string length.
    Regards,
    George
    diff -c dbxml-2.3.10/dbxml/src/dbxml/nodeStore/NsEventWriter.cpp dbxml-2.3.10.patch/dbxml/src/dbxml/nodeStore/NsEventWriter.cpp
    *** dbxml-2.3.10/dbxml/src/dbxml/nodeStore/NsEventWriter.cpp    Fri Nov  3 12:26:11 2006
    --- dbxml-2.3.10.patch/dbxml/src/dbxml/nodeStore/NsEventWriter.cpp      Thu Mar 15 13:58:13 2007
    *** 234,239 ****
    --- 234,241 ----
            CHECK_NULL(text);
            CHECK_SUCCESS();
    +       if (!length)
    +               length = ::strlen((const char *)text);
            if (!_current)
                    throwBadWrite("writeText: requires writeStartDocument");
            try {
    *** 413,418 ****
    --- 415,422 ----
            CHECK_NULL(dtd);
            CHECK_SUCCESS();
    +       if (!length)
    +               length = ::strlen((const char *)dtd);
            if (_current) {
                    if (!_current->isDoc())
                            throwBadWrite("writeDTD: must occur before content");
    diff -c dbxml-2.3.10/dbxml/src/dbxml/nodeStore/NsWriter.cpp dbxml-2.3.10.patch/dbxml/src/dbxml/nodeStore/NsWriter.cpp
    *** dbxml-2.3.10/dbxml/src/dbxml/nodeStore/NsWriter.cpp Tue Jan  2 16:01:14 2007
    --- dbxml-2.3.10.patch/dbxml/src/dbxml/nodeStore/NsWriter.cpp   Thu Mar 15 13:59:25 2007
    *** 326,331 ****
    --- 326,333 ----
                    needsEscape = false;
            else
                    needsEscape = true;
    +       if (!length)
    +               length = ::strlen((const char *)chars);
            writeTextWithEscape(type, chars, length, needsEscape);
    *** 336,341 ****
    --- 338,345 ----
                                  bool needsEscape)
            if(_entCount == 0) {
    +               if (!len)
    +                       len = ::strlen((const char *)chars);
                    if ((type == XmlEventReader::Characters) ||
                        (type == XmlEventReader::Whitespace)) {
                            char *buf = 0;
    *** 381,386 ****
    --- 385,392 ----
      NsWriter::writeDTD(const unsigned char *data, int len)
            if(_entCount == 0) {
    +               if (!len)
    +                       len = ::strlen((const char *)data);
                    _stream->write(data, len);
      }

  • SQL loader and stream files with new line '

    I have been trying unsuccessfully to load EDI files using SQL loader. The problem
    is that the lines are terminated by ' and when I use the stream file option it does
    not recognise the line terminator given. As I understand it from the documentation
    this should work - but it does not. I have also used the Hex option with no better
    result. Does anyone have any ideas ?
    I can and have used tr "[']" "[\n]" in Unix to convert the ' to newlines - I just
    wonder am I missing something in SQL loader which will allow me to do this ?
    This is the sql loader control file
    LOAD DATA
    INFILE 'WS860685.MFD' "Str ''' "
    BADFILE 'WS860685.bad'
    DISCARDFILE 'WS860685.dsc'
    INTO TABLE "DUND1"."EDI_LOADED_TEMP"
    REPLACE
    FIELDS TERMINATED BY '+'
    TRAILING NULLCOLS
    (L1,
    L2,
    L3,
    L4,
    L5,
    L6,
    L7,
    L8,
    L9,
    L10,
    L11,
    L12,
    L13,
    L14,
    L15,
    L16,
    L17,
    L18,
    L19,
    L20,
    L21,
    L22,
    L23,
    L24,
    L25,
    L26,
    L27,
    L28,
    L29,
    L30,
    L31,
    L32,
    L33,
    L34,
    L35,
    L36,
    L37,
    L38,
    L39,
    L40,
    LNO)
    Heres a sample of the data
    UNB+UNOA:2+5398888501357+5398888501838+080306:0737+395+ DESADV+++1'UNH+0001+DESADV:D:93A:UN:EAN004'

    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:6020061915147
    answers this question perfectly

Maybe you are looking for

  • Email Notification to Approver - PCR Approval Process

    Hi, We are in the process of implementing PCR Approval using MSS . And as per requirement , we are supposed to send email notification to the Approver Outlook mail box - as and when the Appoval work item is delivered to the Approver's UWL. By adding

  • Receive email and app alerts -- but no new updates

     I'm using the MyFico 3B monitoring, and several times, I have received an email and/or app notification of a new alert.. However, when I view my alerts on either the app or the myfico website, there are no new alerts.  Example:6/29/2015 5:39 PMDear

  • Audigy 2 and new dri

    I read through the posts but did not find an answer. I have a Falcon NW computer built in December of 2003 and it came with the Audigy 2 card. I have used Auto update before with no problems. I ran it a couple of days ago and it recognized my card an

  • New ipod, can't get it to download from PC.

    I have just purchased my first iPod (60GB). Have sucessfully loaded the software onto my Toshiba laptop, incerted a CD and imported the songs, but when I connect the actual iPod through the USB cable, the iPod flashes 'Do not disconnect'. Nothing els

  • Error 1335 Message

    I get a message saying 'Error 1335...The cabinet file 'Data1.cab' is currupt and cannot be used. I have searched it on this website and it guides me through some tips but this does not work. Any ideas?????? IPod Mini   Windows XP