String concat problem

Hi folks,-
i know this question might be very simple but i just cannot see what i am doing wrong here.
String stringA, stringB, stringC;
stringA= new String();
stringB= new String();
stringC= new String();
stringA = null;
stringB = "TRUE";
stringC = "Error:";
stringA.concat(stringB); // my code stops and quits here w/o error
// other codewhat is wrong here?
thanks much

could you then please explain the following?
public String concat(String str)Concatenates the
specified string to the end of this string.
If the length of the argument string is 0, thenthis
String object is returned. Otherwise, a new String
object is created, representing a charactersequence
that is the concatenation of the charactersequence
represented by this String object and thecharacter
sequence represented by the argument string.
Examples:
"cares".concat("s") returns "caress"
"to".concat("get").concat("her") returns"together"
Parameters:
tr - the String that is concatenated to the end of
this String.
Returns:
a string that represents the concatenation of this
object's characters followed by the stringargument's
characters.
Throws:
NullPointerException - if str is null.It returns a new String, which you are
throwing away. Change your code like this:
stringA = stringA.concat(stringB);
and then you'd get somewhere.yes, it makes sense but the description does not say this.
i think that will work but my problem is with the description of this
concat operation on the java web site.
thanks for the help

Similar Messages

  • String concat PROBLEM??? Please Help

    I have this strange Question regarding String concat
    If I say:
    String str = "Welcome";
    str.concat(" to Java");
    System.out.println(str);
    The output is: Welcome.
    How do I get the output to Welcome to Java??

    I have this strange Question regarding String concat
    If I say:
    String str = "Welcome";
    str.concat(" to Java");
    System.out.println(str);
    The output is: Welcome.
    How do I get the output to Welcome to Java??
    The problem is that String is immutable, The String you have held in str does not change, rather a new Srtring is returned. So all yo have to do is grab the new String
    str = str.concat("to Java");
    or use the new String without keeping it.
    ie
    System.out.println(str.concat("to Java"));

  • XSLT concat() problem.

    Help guys, this XSLT is getting me down!
    Im quite simply trying to take a string, and replace tabs with 4 non-breaking space characters.
    Can someone please explain to me why the following template doesnt work? It should take in a string, perform the replacement in a recursive fashion, and finally print it out.
    Any help is greatly appreciated.
    Cheers,
    Lee.
         <xsl:template name="substitute">
              <xsl:param name="string" />
              <xsl:param name="from" select="'&#9;'" />
              <xsl:param name="to">
                   &#160;&#160;&#160;&#160;
              </xsl:param>
              <xsl:choose>
                   <xsl:when test="contains($string, $from)">                    
                        <xsl:call-template name="substitute">                         
                             <xsl:with-param name="string" select="concat(substring-before($string, $from), $to, substring-after($string, $from))" />
                             <xsl:with-param name="from" select="$from" />
                             <xsl:with-param name="to" select="$to" />
                        </xsl:call-template>
                   </xsl:when>
              <xsl:otherwise>
                   NO MORE SUBSTITUTION REQUIRED - FINAL STRING IS : <xsl:value-of select="$string"/>
              </xsl:otherwise>
              </xsl:choose>
         </xsl:template>

    Help guys, this XSLT is getting me down!
    Im quite simply trying to take a string, and replace
    tabs with 4 non-breaking space characters.
    Can someone please explain to me why the following
    template doesnt work? It should take in a string,
    perform the replacement in a recursive fashion, and
    finally print it out.
    Any help is greatly appreciated.
    Cheers,
    Lee.
         <xsl:template name="substitute">
              <xsl:param name="string" />
              <xsl:param name="from" select="'     '" />
              <xsl:param name="to">
                   ����
              </xsl:param>
              <xsl:choose>
                   <xsl:when test="contains($string, $from)">                    
                        <xsl:call-template name="substitute">                         
    <xsl:with-param name="string"
    ing" select="concat(substring-before($string, $from),
    $to, substring-after($string, $from))" />
                             <xsl:with-param name="from" select="$from" />
                             <xsl:with-param name="to" select="$to" />
                        </xsl:call-template>
                   </xsl:when>
              <xsl:otherwise>
    NO MORE SUBSTITUTION REQUIRED - FINAL STRING IS :
    : <xsl:value-of select="$string"/>
              </xsl:otherwise>
              </xsl:choose>
         </xsl:template>
    It is not concat() problem, it is a recursion problem -- too many recursive calls.
    I wouldn't recommand using recursion in XSL, yeah, it works, but you can't increase the stack size without restarting the JVM...
    anyway, you can use translate function to do replacing, also you can call a java extension method to do string replacement. it is cleaner anyway and more efficient anyway.

  • String.concat() vs + operator in strings concatenations

    Whats the difference between String.concat() and + operator in strings concatenation?
    I cant find any functional one.
    Are there any performance differences?
    Thanks

    TM-Nite wrote:
    Whats the difference between String.concat() and + operator in strings concatenation?
    I cant find any functional one.There isn't any for all one can tell from the API docs. More details would be up to the String implementation.
    Are there any performance differences?No. Both are bad if repeated a lot, as long as there aren't exclusively compile-time constants involved. Use StringBuilder/StringBuffer instead, in those cases.

  • Removing characters from a String (concats, substrings, etc)

    This has got me pretty stumped.
    I'm creating a class which takes in a string and then returns the string without vowels and without even numbers. Vowels and even characters are considered "invalid." As an example:
    Input: "hello 123"
    Output: "hll 13"
    The output is the "valid" form of the string.
    Within my class, I have various methods set up, one of which determines if a particular character is "valid" or not, and it is working fine. My problem is that I can't figure out how to essentially "erase" the invalid characters from the string. I have been trying to work with substrings and the concat method, but I can't seem to get it to do what I want. I either get an OutOfBoundsException throw, or I get a cut-up string that just isn't quite right. One time I got the method to work with "hello" (it returned "hll") but when I modified the string the method stopped working again.
    Here's what I have at the moment. It doesn't work properly for all strings, but it should give you an idea of where i'm going with it.
    public String getValidString(){
              String valid = str;
              int start = 0;
              for(int i=0; i<=valid.length()-1; i++){
                   if(isValid(valid.charAt(i))==false){
                             String sub1 = valid.substring(start, i);
                             while(isValid(valid.charAt(i))==false)
                                  i++;
                             start=i;
                             String sub2 = valid.substring(i, valid.length()-1);
                             valid = sub1.concat(sub2);
              return valid;
         }So does anybody have any advice for me or know how I can get this to work?
    Thanks a lot.

    Thansk for the suggestions so far, but i'm not sure how to implement some of them into my program. I probably wasn't specific enough about what all I have.
    I have two classes. One is NoVowelNoEven which contains the code for handling the string. The other is simply a test class, which has my main() method, used for running the program.
    Here's my class and what's involved:
    public class NoVowelNoEven {
    //data fields
         private String str;
    //constructors
         NoVowelNoEven(){
              str="hello";
         NoVowelNoEven(String string){
              str=string;
    //methods
         public String getOriginal(){
              return str;
         public String getValidString(){
              String valid = str;
              int start = 0;
              for(int i=0; i<=valid.length()-1; i++){
                   if(isValid(valid.charAt(i))==false){
                             String sub1 = valid.substring(start, i);
                             while(isValid(valid.charAt(i))==false)
                                  i++;
                             start=i;
                             String sub2 = valid.substring(i, valid.length()-1);
                             valid = sub1.concat(sub2);
              return valid;
         public static int countValidChar(String string){
              int valid=string.length();
              for(int i=0; i<=string.length()-1; i++){
                   if(isNumber(string.charAt(i))==false){
                        if((upperVowel(string.charAt(i))==true)||lowerVowel(string.charAt(i))){
                             valid--;}
                   else if(even(string.charAt(i))==true)
                        valid--;
              return valid;
         private static boolean even(char num){
              boolean even=false;
              int test=(int)num-48;
              if(test%2==0)
                   even=true;
              return even;
         private static boolean isNumber(char chara){
              boolean number=false;
              for(int i=0; i<=9; i++){
                   if((int)chara-48==i){
                        number=true;
              return number;
         private static boolean isValid(char chara){
              boolean valid=true;
              if(isNumber(chara)==true){
                   if(even(chara)==true)
                        valid=false;
              if((upperVowel(chara)==true)||(lowerVowel(chara)==true))
                   valid=false;
              return valid;
    }So in my test class i'd have something like this:
    public class test {
    public static void main(String[] args){
         NoVowelNoEven test1 = new NoVowelNoEven();
         NoVowelNoEven test2 = new NoVowelNoEven("hello 123");
         System.out.println(test1.getOriginal());
         //This prints hello   (default constructor string is "hello")
         System.out.println(test1.countValidChar(test1.getOriginal()));
         //This prints 3
         System.out.println(test1.getValidString());
         //This SHOULD print hll
    }

  • "dynamic" String concat in Expression language

    I would like to do something like (in Java)
    String s = flag? "this" : value + "that";in EL it would be #{flag ? 'this' : value + 'that'} but this leads to an error because it tries to add as numbers and not concat as strings.
    how can I do this?
    thanks

    maurozoom wrote:
    thanks
    I've been googling for the whole day with no answer.You are terrible at it then.
    >
    I think there's no solution for my problem in ELHere are two search results which contain solutions to your problem from the search I posted:
    http://www.velocityreviews.com/forums/t133287-el-concat-strings.html
    http://marc.info/?l=myfaces-user&m=114123737923937&w=2

  • Setting input fields to an empty string BIG PROBLEM

    Hi Rob, thanks for your rerply, It makes sense alright, but I am using 2 seperate input fields. I have discovered what is causing the problem .
    After the user types into the inputfield and moves on to a different frame, I have set the input field to an empty string and this is what is causing the problem.
    I have tried setting the input field to an empty string in a movie script and on individual sprites and the first right answer is not excepted.I have to type in the right answer twice to get get a right response. I am actually using three seperate input fields in total, each with a different name and behavior. Even If I use one input field I still have the same problem. Its driving me crazey. Any Ideas.
    Anne

    I believe that the FIM Service always does trims on string, so you may be out of luck.
    What is your scenario / what are you trying to accomplish by setting a space in an attribute? A space is not an empty string in my definition.
    Regards, Soren Granfeldt
    blog is at http://blog.goverco.com | facebook https://www.facebook.com/TheIdentityManagementExplorer | twitter at https://twitter.com/#!/MrGranfeldt

  • Is this a CONCAT problem re: David Powers, or a Magic Quotes problem...

    I've tried to figure this out with the posts (and some info
    on David's site, etc), and I just can't seem to figure out the real
    problem.
    I'm working on a tutorial and I can't figure out if the error
    message is correct and it's improper coding inserted by DW (and if
    so, I can't figure out what to correct) or
    If this is a problem with DW8.0.2 along the lines of what the
    hotfix that seems to be so hard to get will fix, or
    If this is along the lines of an example of why magic quotes
    should be turned off, and if so, where/how do I turn them off, and
    will that correct the code, and if not, how would it be properly
    corrected?
    Here is the error message:
    Parse Error: parse error, unexpected '=', expecting ',' or
    ')' in <thefile> on line 34.
    Here is the code it is referencing:
    32 $Search_rsSearch = "abc";
    33 if (isset(#txtSearch#)) {
    34 $Search_rsSearch = (get_magic_quotes_gpc()) ? #txtSearch#
    : addslashes(#txtSearch#);
    35 }
    36 mysql_select_db($database_dorknozzle, $dorknozzle);
    37 $query_rsSearch = sprintf("SELECT * FROM EmployeeStore
    WHERE ItemName LIKE CONCAT('%%', %s,
    '%%')", GetSQLValueString($Search_rsSearch, "text"));
    38 $rsSearch = mysql_query($query_rsSearch, $dorknozzle) or
    die(mysql_error());
    39 $row_rsSearch = mysql_fetch_assoc($rsSearch);
    40 $totalRows_rsSearch = mysql_num_rows($rsSearch);
    I'm using php4.4.4, mysql5.0.24, apache2.2.3
    Thank You,
    Jeff G.

    xViPERed wrote:
    > If this is a problem with DW8.0.2 along the lines of
    what the hotfix that
    > seems to be so hard to get will fix,
    That will fix part of your problem, but the error is caused
    by something
    else:
    > Here is the error message:
    >
    Parse Error: parse error, unexpected '=', expecting ',' or
    ')' in
    > <thefile> on line 34.
    >
    > Here is the code it is referencing:
    > 32 $Search_rsSearch = "abc";
    > 33 if (isset(#txtSearch#)) {
    > 34 $Search_rsSearch = (get_magic_quotes_gpc()) ?
    #txtSearch# :
    > addslashes(#txtSearch#);
    > 35 }
    # is one of the PHP characters used to comment out part of a
    script. I
    suspect that you have got this from the Dreamweaver help
    files, which
    are particularly unhelpful on this point. The show the
    runtime value
    expression as #formFieldName#, which is ColdFusion style, not
    PHP. You
    need to replace #txtSearch# with something like
    $_GET['search'] or
    $_POST['search'].
    What makes things worse is that the code inserted by 8.0.2
    without the
    hotfix is also incorrect. Line 34 should be something like
    this:
    $Search_rsSearch = $_GET['search'];
    Line 37 is also wrong.
    > 37 $query_rsSearch = sprintf("SELECT * FROM
    EmployeeStore WHERE ItemName LIKE
    > CONCAT('%%', %s,
    > '%%')", GetSQLValueString($Search_rsSearch, "text"));
    It should be this:
    $query_rsSearch = sprintf("SELECT * FROM EmployeeStore WHERE
    ItemName
    LIKE %s", GetSQLValueString("%" . $Search_rsSearch . "%",
    "text"));
    David Powers
    Adobe Community Expert
    Author, "Foundation PHP for Dreamweaver 8" (friends of ED)
    http://foundationphp.com/

  • Iif and concat problem in email body - solution

    Hi all, it is not a question, just some information if somebody will try to do it:
    If you want to send an email from workflow and use the IIf function with concatenated results, the concat syntax in the help will not work.
    The solution is: Use + character in place of || and so on :)
    For exlampe:
    %%%IIf(PRE('<dDate_field1_ITAG>')<>[<dDate_field1_ITAG>],'Any text '+PRE('<dDate_field1_ITAG>')+'-->'+[<dDate_field1_ITAG>], '')%%%
    The result when the field HAD a value and it is changing to another: Any text 11/11/2011 --> 12/11/2011
    If the field is changing from NULL to something, use this:
    %%%IIf(IfNull(PRE('<dDate_field1_ITAG>'),0)<>[<dDate_field1_ITAG>],'Any text'+PRE('<dDate_field1_ITAG>')+'-->'+[<dDate_field1_ITAG>], '')%%%
    And if U want to see the every change (null -> value, value -> value, and value -> null), use this beauty:
    %%%IIf(IfNull(PRE('<dDate_field1_ITAG>'),0)<>[<dDate_field1_ITAG>] OR ([<dDate_field1_ITAG>] IS NULL AND PRE('<dDate_field1_ITAG>') IS NOT NULL),'Any text'+PRE('<dDate_field1_ITAG>')+'-->'+[<dDate_field1_ITAG>], '')%%%
    Regards,
    A.

    >
    my problem is my email body is
    please clik on this link www.gmail.com
    iii am concating the text please clik on this link ||' '||www.gmail.com
    but in email www.gmail.com is shown on text only.Correct. As the e-mail body is in text/plain MIME format.
    If you want to use formatting in the e-mail body, you need to create a text/html body. At [RFC FAQs|http://www.faqs.org/rfcs/rfc-titles.html], refer to the following RFCs:
    - RFC 2049 - Multipurpose Internet Mail Extensions (MIME) Part Five: Conformance Criteria and Examples
    - RFC 2048 - Multipurpose Internet Mail Extensions (MIME) Part Four: Registration Procedures
    - RFC 2047 - MIME (Multipurpose Internet Mail Extensions) Part Three: Message Header Extensions for Non-ASCII Text
    - RFC 2046 - Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types
    - RFC 2045 - Multipurpose Internet Mail Extensions (MIME) Part One: Format of Internet Message Bodies
    In simple terms, your e-mail message body needs to look something like this:
    Subject: Test E-mail
    From: "John Doe" <[email protected]>
    To: "Jane Doe" <[email protected]>
    Content-Type: multipart/alternative; boundary="=-2zP89iYM0w6fRrmCDsDv"
    Mime-Version: 1.0
    --=-2zP89iYM0w6fRrmCDsDv
    Content-Type: text/plain
    Content-Transfer-Encoding: 7bit
    This is the start of the e-mail message in plain text format.
    blah blah..
    --=-2zP89iYM0w6fRrmCDsDv
    Content-Type: text/html; charset="utf-8"
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 TRANSITIONAL//EN">
    <html>
    This is the start of the e-mail message in HTML text format.
    </html>
    --=-2zP89iYM0w6fRrmCDsDv--

  • String check problem

    I have a doozy of a problem on my hands. My company has introduced a password policy that every user must me now. Some of my criteria is that a password must contain at least one symbol and at least one number. In 10g I can use REGEXP_LIKE function, but I am running 9i. I have tried to use translate, OWA_PATTERN function, everthing. How can I take a string variable, and test to see if there is a symbol in the text or a number. I want to be able to return a true/false value?
    Please advise?

    Like Kamal says, use built-in functionality FIRST.
    Failing that, presumably you would write something like this (I forget the exact naming standard for the password verify function).
    CREATE FUNCTION valid_password (
       p_password IN VARCHAR2)
       RETURN BOOLEAN
    IS
       FUNCTION contains_at_least_one (
          p_string IN VARCHAR2,
          p_characters IN VARCHAR2)
          RETURN BOOLEAN
       IS
       BEGIN
          RETURN LENGTH (TRANSLATE (p_string, 'X' ||
            p_characters, 'X')) < LENGTH (p_string);
       END;
    BEGIN
       RETURN contains_at_least_one (p_password, '0123456789')
          AND contains_at_least_one (p_password, '!£$%^&*(){}~@??|<>');
    END;

  • String overlapping problem in mx:List caused by wordWrap

    I'm using mx:List to display String items. The dataProvider is XMLListCollection. Some of the String is long so it takes more than one rows. I use the wordWrap to display the long String in more than one rows. The problem is that the next String item will overlapping with the long String. The mx:List can not adjust the vertical space for the Strings that needs more than one rows dynamically. Any suggections?

    Here is solution: variableRowHeight="true"

  • String offset problem

    Hi,
    I'm using 1.4.2 at the moment.
    I got the problem below and have no idea how to solve it. The program portion is:
    String x = node.getText();
    The node.getText() should contain value = "\n\r"
    However, it always return me "\r" only.
    I checked with the debugger and found that when I change the offset value of x to 0, it can return me "\n". However, the original offset value is always kept as 1. That's the reason why it always return me "\r".
    Can anyone help and tell me how to get the value "\n" in this case, i.e. any String method which I can check and get the offset value 0 from the string x.
    Thanks million in advance.
    Regards,
    Eric

    Can anyone help and tell me how to get the value "\n"
    in this case, i.e. any String method which I can
    check and get the offset value 0 from the string x.
    x.charAt(0);is probably what you mean.

  • String item problem

    I use mobility pack visual designer.
    When I create a string item in visual screen designer it looks like that:
    Title
    <text>
    but after i run my app it looks different
    Title <text>
    Why there's no line break?
    When I try to add the line break manually it doesn�t work because screen designer property editor adds to the code \\n when I put \n
    so generated code looks like that
    stringItem1 = new StringItem("stringItem1\\n", "<Enter Text>");  and I cannot edit it manually because generated code is blocked by net beans
    I can initialize my stringItem object one again
    stringItem2 = new StringItem("stringItem2\n", "<Enter Text>");  but I thing that�s very stupid to reinitialize an object twice
    And the line break after title doesn't solve my problem because if the title is too long the device will automatically brake the line and I�ll get this
    A long long title........
    <text>
    one empty line because of that break
    Any ideas?
    I don�t want to use textField because when you set it to uneditable its color becomes gray.

    Check the actual URL up in the location bar. Your comma may actually be dropping out there, because it isn't encoded such that in value commas can be differentiated from delimiters, so the fields aren't lining up in the URL properly.
    When you go to a page that takes in parameters for assignment in the link, it has 2 fields. The first is the comma separated list of the item names on the page to assign, which wouldn't contain commas in their names. The other field in the URL is a comma separated list of values to be assigned to the previous list. Since these values aren't encoded, the comma in the value is picked up as delimiter and not a part of the value. I have an example I can load up to apex.oracle.com if you need.
    -Richard
    Edited by: rwendel on Aug 13, 2009 11:51 AM

  • Passing string data problem

    Dear readers,
    I came across some problem in my labview VI where I try to pass a string (stored in a local variable) to other string variables connected to that local variable. In this case, I have a local string variable called 'output_string1', which contains the string '123'. I have it set to 'write'. Then I connect 3 string Indicators to this local variable, called 'string1', 'string2', and 'string3'. I would expect these connected string indicators to also contain the string '123', as they're simply connected to the 'output_string1'. But the strange thing is that only 'string2', and 'string3' contains '123', but 'string1' contains a '.' (ie a dot). Would someone be able to provide some kind advice about what I might be doing wro
    ng to get this result? I've attached the vi that I was making that demonstrates what I described. Thank you very much for your help.
    Attachments:
    remove_trailing_zeros_subvi.vi ‏78 KB

    In the last sequence you have intended to concatinate a string from three inputs; the local variable before, a "." and a local of string1. BUT instead of reading the local of string1 you have it in write mode...and the "." is wired into it! So you really wire 123 to that indicator as well in sequence 5, but it is immediately overwritten by a "." in the next sequence.
    That aside though there's two other things about the code that needs to be commented:
    a) You use locals as you would use them if G was a textual language; like variables. In G though we try to avoid locals all together, in G the wire is the variable! The wire in addition ensures the next thing the code lacks; execution control.
    b) Instead of sequences, use data flow. By working
    with the wire instead of locals you can ensure that things execute in the order you want it to, without the need for a sequence structure. And without a sequence structure the code becomes much easier to read and maintain.
    I have attached a modified version of your code that applies these two conversions to a "G" way of programming.
    Removing trailing zeroes can be done much easier though, attached is also an example of one such way.
    MTO
    Attachments:
    remove_trailing_zeros_Simplified.vi ‏45 KB
    remove_trailing_zeros_improved.vi ‏22 KB

  • String compare problem

    I try to compare 2 strings with compareTo/equalTo, but it's not working, those 2 funcs always return ture.
    public boolean chMark(String name, String test, String newMark)
              boolean flag = false;
              for(int i = 0; i < course.getNumOfStd(); i++)
                   if(course.getStd().getName().compareTo(name)==0)//here is problem;
                        Student tempStd = course.getStd()[i];
                        for(int j = 0; j < tempStd.getMark().getNumOfTests(); j++)
                        if(tempStd.getMark().getTestArray()[j].getTitle().compareTo(test)==0);//here is problem;
                             int mark = Integer.parseInt(newMark);                    }
              return flag;
    Can anybody tell me why?
    REGARDS,
    Elton

    equals() would read more naturally than compareTo()==0. But, in
    either case, use System.out.println() to write the two strings before
    you compare them. This is to check that you are comparing what
    you think you're comparing.System.out.println("name from course is " + course.getStd().getName());
    System.out.println("name is " + name);
    if(course.getStd()[i].getName().compareTo(name)==0)//here is problem;
    System.out.println("name from couse and name compared equal");
    // etc

Maybe you are looking for