Concat a newline to the  string

I want to concatinate a new line to the existing string and then concatinate some other string.
My question is what should i use to concatinate a new line

No doubt, Thomas.
You might want to read this:
http://wiki.java.net/bin/view/Javapedia/AlwaysUseString
ufferMisconception
MODWell, maybe you should read that article one more time and more carefully yourself.
I was concatenating three Strings, only one of those is literal String. ;-)
My post was not intended to correct the previous answers in their use of string concatenation, I was too slow in typing to be the first on to answer. :-(
On the other hand, it's true that I don't like using the overloaded + operator - it's a pure style thingie to me with the beneficial side effect of a performance increase in large loops ... anyways I never understood why Java would disallow operator overloading but then being inconsistent when it came to Strings.

Similar Messages

  • 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

  • A quick way to count the number of  newlines '/n' in string of 200 chars

    I am trying to establish the number of lines that a string will generate.
    I can do this by counting the number of '/n' in the string. However my brute force method (shown below) is very slow.
    Normally this would not be a problem on a 2800mhz Athlon (Standard) PC this takes < 1 second. However this code resides within a speed critical loop (not shown). The code shown below is a Achilles heal as far as the performance of this speed critical loop goes.
    Can anyone suggest a faster way to count the number of �/n� (new lines) within a text string of around 50- 1000 chars, given that there may be 10 � 100 newline chars. Speed is a very important factor for this part of my program.
    Thanks in advance
    Andrew.
        int lineCount =0;
        String txt = this.getText();
        //loop throught text and count the carridge returns
        for (int i = 0; i < txt.length(); i++)
          char ch = txt.charAt(i);
          if (ch == '\n')
           lineCount ++;
        }//end forMessage was edited by:
    scottie_uk
    Message was edited by:
    scottie_uk

    Well, here is a C version. On my computer the Java version (reply 9 above) is slightly faster than C. YMMV. For stuff like this a compiler can be hard to beat even with assembler, as you need to do manual loop unrolling and method inlining which turn assembly into a maintenance nightmare.
    // gcc -O6 -fomit-frame-pointer -funroll-loops -finline -o newlines.exe newlines.c
    #include <stdio.h>
    #include <string.h>
    #if defined(__GNUC__) || defined(__unix__)
    #include <time.h>
    #include <sys/time.h>
    #else
    #include <windows.h>
    #endif
    #if defined(__GNUC__) || defined(__unix__)
    typedef struct timeval TIMESTAMP;
    void currentTime(struct timeval *time)
        gettimeofday(time, NULL);
    int milliseconds(struct timeval *start, struct timeval *end)
        int usec = (end->tv_sec - start->tv_sec) * 1000000 +
         end->tv_usec - start->tv_usec;
        return (usec + 500) / 1000;
    #else
    typedef FILETIME TIMESTAMP;
    void currentTime(FILETIME *time)
        GetSystemTimeAsFileTime(time);
    int milliseconds(FILETIME *start, FILETIME *end)
        int usec = (end->dwHighDateTime - start->dwHighDateTime) * 1000000L +
         end->dwLowDateTime - start->dwLowDateTime;
        return (usec + 500) / 1000;
    #endif
    static int count(register char *txt)
        register int count = 0;
        register int c;
        while (c = *txt++)
         if (c == '\n')
             count++;
        return count;
    static void doit(char *str)
        TIMESTAMP start, end;
        long time;
        register int n;
        int total = 0;
        currentTime(&start);
        for (n = 0; n < 1000000; n++)
         total += count(str);
        currentTime(&end);
        time = milliseconds(&start, &end);
        total *= 4;
        printf("time %ld, total %d\n", time, total);
        fflush(stdout);
    int main(int argc, char **argv)
        char buf[1024];
        int n;
        for (n = 0; n < 256 / 4; n++)
         strcat(buf, "abc\n");
        for (n = 0; n < 5; n++)
         doit(buf);
    }

  • How to add newline into a string

    I need to define a string which contains a newline,
    what i did is :
    String newline = new String();
    newline = "\n";
    but when i add new line to other string, and print it out,
    seems it is not working....
    Anrybody knows why?
    thanks~

    Please keep in mind that newlines differ between platforms. The "\n" is very well known, however in the Windows world a newline is actually "\r\n". Thankfully you may retrieve this value from the JVM.
    String newline = System.getProperty("line.seperator");Also System.out.println() will automatically append the correct newline at the end.
    Meaning that
    System.out.println("Hello");
    System.out.print("Hello" + newline);are esentially the same.

  • Join the String (Urgent)

    I have 5 records, lets say column names are:
    ID ==> varchar (25)
    Group ==> varchar(25)
    ID GROUP
    12 Group_1
    34 Group_1
    55 Group_1
    66 Group_2
    22 Group_2
    I need to join the IDs vertically with a seperator ","....
    the result should be like this:
    Total IDs GROUP
    12,34,55 Group_1
    66,22 Group_2
    I can't find any functions that I can do this vertically, I can
    only find a function "SUM" to sum the number for each particular
    group but not for joining the string.
    Please help ~

    I think you need to flip the table. Well Try this with the help
    of Decode with concate.
    Otherwise go with union. It will work.
    --Thanks                                                                                                                                                                                                                                                                                               

  • How to send really Chinese word, not the string "&# number " to web browser

    Each Chinese word on page sending to web browser is translated to a string in form "&#<number>" by default, it's a problem when Chinese word is included in url. How to specify sending really Chinese word, not the string "&#<number>" to web browser?

    Thanks that seems to make much more sense, still having some troubles though.
    Ok so now the majority of it seems to be working and it seems to be sending the String just fine. And I'm having it send the String to the BufferedWriter "out" and then using the newLine() method to send a carriage return but the BufferedReader on "in" seems to not detect the carriage return.
    I have it doing a readLine() so that (as I understand it) it should be blocking, waiting until an end of line character so I assume each call of newLine() should have it pick up something but a quick breakpoint shows that it never stops blocking on readLine().
    I assume the connection is fine because the application running as server uses the socket object returned by the accept() method.
    Is there something I've perhaps misunderstood about the BufferedReader's readLine() method?
    Here's the new version of my netbeans project:
    http://rapidshare.com/files/371224512/KerazehDood.rar
    Also on a different line of questioning, I'm just wondering about socket convention.
    I was thinking it'd be useful in a game similar to what I'm attempting to make to not only send player position information but also client keypress information, I was just wondering, if you're doing something like that would it be frowned upon to use two separate ports? I think it would make the implementation far more legible and easy to structure but wasn't sure if applications usually try to stick to only one port or not.
    Thanks.
    Edited by: ThePermster on Apr 2, 2010 10:54 AM

  • Unable to capture the String[] from a JavaCallOut

    Hi all,
    I am doing an application in which I need to do a java callout which accepts string and return a String array as output. The java class alone is working fine but when I do the Java Callout and pass the string I am getting *"<con:java-content      ref="jcid:-31630335:136f3572827:-3925" xmlns:con="http://www.bea.com/wli/sb/context"/>"* as a response. How should I access array variable in OSB?
    Kindly help me in this.
    Regards
    Phanindra.

    in Java Callouts I would avoid types which are not in THE list of supported types:
    http://docs.oracle.com/cd/E13159_01/osb/docs10gr3/eclipsehelp/ui_ref.html#wp1290279
    java.lang.String[] is supported for INPUT ONLY
    just return some CSV in a String and you will be happy
    or return a XmlObject containing multiple elements
    A con:java-content thingie can be processed only in another Java callout, and not in a OSB message flow....

  • Seperation of contents in the string

    Hi Guru's,
    I was assigned a little bit query related to updation of text for LFA1 object. I would like to expalin my requirement in details. I have 2 texts like Z001 & Z002. Z001 stores range of PRO numbers. Z002 is for display the current PRO number related to perticular vendor. we need to update that Z002 by code it self. Suppose Z001 contains the range like this (ROADWAY 444 100 , ROADWAY 444 999). I need to update Z002 with the next value starting from lower value like
    (ROADWAY 444100,ROADWAY 444 101,ROADWAY 444 102...........). For each vendor length of PRO # may change. Now my problem is how can i seperate alphabates and numerics in this string (ROADWAY 444 100..) for updating Z002 with next PRO#. Kindly help me out in this scenario and your help will be greatly appriciated.
    Regards,
    Ravi.

    Hi Ravi,
    You can split the string into parts..
    DATA : begin of itab OCCURS 0,
                 line type char100,
    end of itab.
    SPLIT z001
         AT space
    INTO TABLE itab.
    Now if you are sure that the 3rd record will be which you need to use..
    Then, LOOP AT itab INDEX 3.
    MOVE itab-line TO w_num.
    w_num = w_num + 1.
    ENDLOOP.
    Thanks and Best Regards,
    Vikas Bittera.
    **Reward if useful**

  • How can labview update the string control (text-edit box) after we have pressed the carriage return key on the keyboard during text-editing within that box?

    Dear readers,
    I have been trying to work out how to get labview to detect the event when a 'string' control has been modified, where the user has finished editing the string either by 1) pressing the enter key on the keyboard, or by 2) taking the focus away from the string control again. For example.. if I use the mouse to click on the string control and then I type 1234 into the box, I would like to have a routine that does something once the user hits the Enter key of the keyboard, or when the user takes the focus away from the string control again by clicking on something else. I would like the routine to respond even when the user didn't change anything in the text box (such as when we mouse-click on the edit box to go into edit mode, and then mouse-click on something else to remove the focus with no changes to the contents in edit-box).
    The purpose of my routine is to have a edit-box for a user to change for example the centre-frequency of a vector network analyser, so that the centre-frequency of the network analyser can change once the user finishes entering a new value in the text-edit box by hitting Enter key after the number is keyed in. Even if the user has clicked on the edit box, but changes their mind by mouse-clicking on something else to remove focus from the edit box, I would still like labview to detect the event when the control loses focus, so that the centre frequency can be updated anyway (to the same value that was already in the edit box).
    So far, I've tried set the string control option to 'limit to single line', so that I can try to scan for a carriage return .. '\n' ... pattern in the string. Unfortunately this doesn't work because labview doesn't seem to attach the '\n' to the end of that single line.
    Could someone please suggest ways to set a flag when a user hits Enter during text-edit mode of a string control, or when focus has been removed from the string control?
    While I've only described my problem for controlling a single control parameter on the gpib device, I'd like to make this feature work so that I can do the same kind of thing with other control parameters as well.
    Thanks so much in advance.
    Kenny

    Hi Kenny,
    instead of using the event structure, you can directly achieve to what you want by the KeyFocus property of the string control.
    - Enable Limit to single line option
    - Create the property KeyFocus in read mode and connect an indicator
    Each time you click on the string to modify it KeyFocus is True; when you click away or hit Enter KeyFocus is False.
    You can toggle your settings when KeyFocus changes from True to False.
    Alberto

  • How to count number of vowels in the String?

    Write a program that calculates the total number of vowels contained in the String" Event Handlers is dedicated to making your event a most memorable one."
    Please help!

    http://leepoint.net/notes/javanotes/40other/20examples/60Strings/example_countVowels.html

  • I would like to do a program that have one string control and one string indicator, any character that I type in the string control in the same time it will be appear in another string (indicator). How can help me?

    I would like to do a program that have one string control and one string indicator, any character that I type in the string control in the same time it will be appear in another string (indicator). How can help me?

    Why not use an event
    Add a While Loop, inside the loop add the Event Sructure.
    Now in the event structure selecd the String Controls.value change event to
    react
    and the new value inside the event that you get,( connect to the String
    indicator box.
    On Sun, 10 Aug 2003 15:58:47 -0500 (CDT), WiltonFilho wrote:
    > I would like to do a program that have one string control and one
    > string indicator, any character that I type in the string control in
    > the same time it will be appear in another string (indicator). How can
    > help me?
    >
    > I would like to do a program that have one string control and one
    > string indicator, any character that I type in the string control in
    > the same time it will be appear in another string (indicator). How can
    > help me?
    >
    Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/

  • Issue with the String return from com.sap.aii.af.mp.module.ModuleData

    Hi Friends,
    We are developing Adapter for XI using java, XI is giving String in the form of ModuleData, we r getting the String from ModuleData but in the logic we need to split the String in parts based on character '…', but I observed that in the communication channel symbol is showing as ' '.
    We have written the java code based on '…' but splitting is not working, then I tried with the following code
    String[] molecules = null;
    if(filedata.indexOf(" ") != -1){               molecules = filedata.split(" ");
    }else if(filedata.indexOf("?") != -1){
                    molecules = filedata.split("?");
    }else if(filedata.indexOf("…") != -1){
                    molecules = filedata.split("…");     
    Still it is not working, please help in case of ModuleData text splitting..
    Thanks in advance.
    Satinder Saini

    Check with a hex editor, what the  ' '. really is.
    Maybe it is a tab? Then you can use "\t" in a Java progam.
    See also here:
    http://en.wikipedia.org/wiki/ASCII#ASCII_control_characters
    Regards
    Stefan
    Edited by: Stefan Grube on Mar 26, 2008 2:22 PM

  • How do I copy the string portion of an enum into the string portion of a cluster?

    I want to do this for the an entire array of clusters.  I'm trying to use a for loop.  Can't figure out how to parse the string portion of the enum into the string portion of the cluster.
    Alternatively, I'd be happy if I could figure out some way to tie the enum to the array of clusters, but I figure that gets problematic.
    DH
    Solved!
    Go to Solution.

    Dark Hollow wrote:
    OK, let's say that the enumerated type has N elements.  I want to initialize an N element array of strings.  How do I reference each string in the enumerated type to get to each string?
    Easy way to do this is to use GetNumericInfo.vi, part of the Variant library, found in vi.lib\utility\VariantDataType\GetNumericInfo.vi.  Wire your enumeration to the Variant input; one of the outputs is an array of the strings in the enumerated type.
    The more complicated way is a for loop, in which you typecast the iterator terminal value to the enumerated type, then use Format Value.  You can get the maximum value of the enumeration by casting 0 to the enumerated type, then decrementing; cast that back to a numeric and add one to get the right value to wire to the N terminal.
    EDIT: just thought I'd add, since RavensFan's reply popped up while I was writing mine - I don't like the Strings[] approach because it doesn't work on RT targets, and I lost a lot of time once due to this trying to figure out why my code wouldn't run properly on an RT system but worked great on my development computer.

  • How to calculate length of the string in transformation file

    Hello all
    I have tried a number of ways and I am not able to calculate the length of the incoming field in transformation file for my data load. Here is the issue.
    I have an incoming string of length 10 and I need to use it to update multiple dimensions which will need first 2, 4 ,6 , 8 characters respectively.
    Now in transformation file ID=ID(1:2) works perfect. However, the BW InfoObject will have multiple values as shown below:
    ID
    Description
    AB
    Business
    ABCD
    Business Organization
    ABCDEF
    Business Line
    ABCDEFGH
    Product Family
    ABCDEFGHIJ
    Product Line
    ABCDEFGHIJKL
    Brand
    I want to update my dimension for Business Organization. I need to update only the records where the length of the incoming string is 4. If I do ID(1:4), I will get the duplicate records and will see the ID less than 4 characters in rejected records. The latter is not such a big issue but the former one is as I need to fetch the right description as well. The formula should check the length and then only pass the record else a dummy value.
    A formula to achieve this in the transformation file is what I am looking for.
    Regards
    Gajendra

    Thanks Vadim for the quick response!
    I am also trying something similar and really appreciate your input here. However, I am not sure if the conversion is really happening.
    Here is what I have done:
    But the strings <> 4 in length are still passing through.

  • Problems with the Strings Urgent Help needed

    I have a unique problem. I have to retrieve a particular value from a String. I tried using String tokeniser but in vain. I cannot use java.util.regex package to match the expressions as the version of java on the client m/c is 1.1.8 and they are not ready to upgrade the same.
    The string From which I have is a very long one running into more than 100 lines which can vary from case to case all I know is to retrieve the value which is just in front of "TestValue" which occur only once in the String Can Anybody suggest a bettter alternative.
    Thanx.
    ebistrio

    StringTokenize on TestValueHow would you suggest that was done?
    As I understand it StringTokenizer tokens = new StringTokenizer(string, "TestValue"); would not tokenize on the string "TestValue" but on any of the characters 'T', 'e', 's', 't', 'V', 'a', 'l' or 'u'. This is a common java pitfall in my opinion due to bady named parameters (I feel it should be called "delims" not "delim") or in other people's opinion due to bad parameter type (should be a char[] not a string).
    A clearer explanation of the problem would help.

Maybe you are looking for