Using concat for STrings

I'm trying to concat a specified string, ".jpg", to a string of the form:
filestring = afile.getName();
filestring.concat(".jpg");
Why does it not add the .jpg to the end of what filestring is?

Cuz Strings are immutable dingbat. If you'd read the api you might notice concat returns a new string with the value you want, but you're chucking it since you didn't assign the result to a variable.
Options:
1) filestring = afile.getName() + ".jpg"
2) filestring = afile.getName().concat(".jpg");
3) filestring = afile.getName(); filestring = filestring.concat(".jpg");
3) use StringBuffer instead

Similar Messages

  • Question of using concat for databinding

    I am trying to use concat to build up a string for databinding. the code 2 should replace the code 1 here and of course they should have the same output:
    Code 1:
      <textInput text="${uix.current.DepartmentName}"
                 columns="10" readOnly="true"/>
    Code2:
         <textInput columns="10" readOnly="true">
          <boundAttribute name="text">
             <dataObject>
               <concat>
                  <![CDATA[${uix.current.]]>
                  <![CDATA[DepartmentName]]>
                  <![CDATA[}]]>
               </concat>
             </dataObject>
           </boundAttribute>
       </textInput>Code 1 gives out always right out put like "Administration,Marketing...." ,but code 2 gives always "${uix.current.DepartmentName}", the databinding code out. Its not translated correctly as databinding resourse.
    Do You have any idea to solve this problem?
    Best Regards
    Yong

    Hi Arjuna, thanks for your help.
    We are currently investigating how to extend the UIX components in a way to get the good old bc4j components back again.
    We had some understanding problems with the new binding.
    Anyhow a <textInput text="${uix.current[uix.rootAttr.attrName]}}" /> seems to work.
    Regards, Markus

  • Use Operator == for String Comparison

    Hi,
    I would like to know more about the impact of using operator == in String Comparison.
    From the reference I get, it state this :
    "Operator (==) compares two object addresses to see whether it refers to the same object."
    I've tested it with 2 codes as below :
    Code 1:
              String Pass1 = "cosmo";
              String Pass2 = "cosmo";          
    if (Pass1==Pass2)
                   System.out.println("1&2:same");
              else
                   System.out.println("1&2:not same");
    Output : 1&2:same
    Code 2:
              String Pass3 = new String("cosmo");
              String Pass4 = new String("cosmo");
              if (Pass3==Pass4)
                   System.out.println("3&4:same");
              else
                   System.out.println("3&4:not same");
    Output : 3&4:not same
    Can anyone kindly explain why is the result so? If operator == compares the addresses, isn't it that the 1st code should also have the output :"1&2:not same".

    Can anyone kindly explain why is the result so?It's an implementation artifact. Strings are pooled internally and because of that any String literal will be represented by exactly one object reference.
    Knowledge of this shouldn't be utilized though. It's safer to follow the basic rule: Use == to compare object references and equals to compare object values, such as String literals.

  • Using StartsWith for String Comparision in Business rules

    hi,
    I need to compare whether a particular string starts with some pre-defined prefixes. These are bound to change from time to time and hence we wanted to use the business rule engine for this. We declared prefixes using "list of values" vocab and
    defined the set. Now, I hoped to use the String.StartsWith() method but couldn't understand if it can be used.
    As of now, we are creating a method and that will be called with 2 parameters. One the string and other is one of the list of values which we want the string to start with. Is there any better way to do this?
    Praveen Behara
    MCST : BizTalk Server 2006 R2, 2010

    Hi Murugesan,
    I need to match a particular series of numbers... say 12xxx,345xxx,567xxx. I am creating a
    Series as a list and the valid values would be 12, 345, 567. I intend to keep them as prefixes i.e. they are not regular expressions. So, they won't be 12.*, 345.*, 567.*. The idea is to keep the vocab close to requirement
    and away from implementation (typically, for a business user). Now, if I want this setup, how will the implementation with
    Match look like?
    Technically, your above solution would work.. but my way of implementation / thought process is for a different purpose.
    Praveen Behara
    MCST : BizTalk Server 2006 R2, 2010

  • Using wildcards for String compare

    Hello,
    I want my prog to find out all Strings which start with the letters 'File'. How can I make a String compare by using wildcards ?
    Thanx,
    Findus

    You may use the String method startsWith to find strings beginning with File. eg. filename.startsWith("File")
    for more complicated comparisons you might want to use regular expressions.

  • Using CharAt for String Manipulation

    Hi,
    I am new to Java and am taking a Java class. I am trying to put a social security number in "nnn-nn-nnnn" format where n is a digit 0-9. I don't know if it would work with the charAt method of the String class. Does anyone have any suggestions on how to implement this kind of manipulation.
    It would be greatly appreciated!
    Thanks,
    waggypup99

    You could just create a class for social security number.
    e.g.
    public class SSNum{
        private int _num;
        public SSNum(int number){
          _num = number;
          * take number in the form  nnn-nn-nnnn
        public SSNum(String number){
          StringTokenizer st = new StringTokenizer(number,"-");
          StringBuffer numStringB = new StringBuffer(st.nextToken());
          numStringB.append(st.nextToken());
          numStringB.append(st.nectToken());
         _num = Integer.parseInt(numStringB.toString());
       public String toString(){
          //left as fun exercise
    }

  • Clean up output when using concat for two columns?

    Probably a basic questions, but I searched this forum and google and couldn't find an answer, so here it goes...
    I'm trying to concatenate two fields: first_name and last_name
    I'm using the following pl/sql:
    concat(a.first_name, a.last_name)But it runs the name together
    smithjohn And the title shows the following
    concat(a.first_name,a.last_name)And this output is going to a non-technical users, so I don't want them to freak out...
    I've tried this as well
    a.first_name||' '||a.last_nameAnd now the column, I get the following:
    Smith John But the column heading shows
    a.first_name||""||a.last_nameIs there anyway I can clean up the column heading so the end users won't be confused...?
    thanks
    Message was edited by:
    cmmiller

    For renaming the title of the column use an alias with "AS" or just put the alias after the concatenation.
    Examples:
    denunez@XE> select e.first_name||' '||e.last_name as Name from employees e  where rownum <3
      2  ;
    NAME
    Ellen Abel
    Sundar Ande
    denunez@XE> select e.first_name||' '||e.last_name Name from employees e  where rownum <3
      2  ;
    NAME
    Ellen Abel
    Sundar Ande
    denunez@XE> select e.first_name||' '||e.last_name "Employee Name" from employees e where rownum<3;
    Employee Name
    Ellen Abel
    Sundar Ande

  • Why only +String concatation for Operator Overloading ?

    Java does not support operator overloading other than the + operator for addition of two Strings or a number and a String.Why only the + operator and Strings, even when we have a concat() for addition of Strings ?
    Wondering if anyone could provide me some link as to why this only this (+) operator was chosen.
    Thank you for your consideration.
    Edited by: amtidumpti on Apr 27, 2009 6:40 AM
    Edited by: amtidumpti on Apr 27, 2009 6:40 AM

    amtidumpti wrote:
    stevejluke wrote:
    amtidumpti wrote:
    Java does not support operator overloading other than the + operator for addition of two Strings or a number and a String.Why only the + operator and Strings, even when we have a concat() for addition of Strings ? I assume the + was implemented (even with the concat() method present) for simplicity with working with Strings. Why only +? What other operators make sense as String manipulation operators? Why are they useful?We already have String,StringBuilder,StringBuffer for simplicity and manipulations of Strings or may be they were added later,but even then we have this +.Right, and you can use those methods instead of +. But String is a much-used class, has several special attributes given to it, and the + is very self-explanatory when applied to Strings.
    Also would == qualify as the other operator for operator overloading in java ?== has no special meaning for Strings (or really for Objects at all). It has exactly one purpose, to compare the value of the operands provided. When the operands are primitives, it compares their values exactly as you or I would (if the primitive values are equal you get true). When the operands are reference types the value of the references are tested for equality (if they don't hold a reference to the same Object, then == returns false).
    >
    int iAge1=0,iAge2=0;
    String sName1="Java",sName2="Rocks";
    double dMark1=89.02,dMark2=92.0;
    if(iAge1==iAge2)
    System.out.println("HURRAH");
    if(sName1==sName2)
    System.out.println("HURRAH");
    if(dMark1==dMark2)
    System.out.println("HURRAH");Also in case of boolean :
    boolean bFlag1=false,bFlag2=true;
    if(bFlag1=bFlag2)
    System.out.println("Value Assignment done");Here is " = " working not only as a assignment operator as well as conditional operator ?
    Thanks for your consideration.

  • How to use multiple VCI strings for lap 1300 and 1200 (option 60) in one pool?

    Hi All,
    Hope to you a very happy new year,
    I have two differnt LAP 1300 and 1200 in my network and I need to add theme to the WLC,
    I successed to add one of theme by the option 60 in the DHCP pool at the Core SW,
    So my quetion is below:
    How to use multiple VCI strings for lap 1300 and 1200 (option 60) in one pool?
    Thanks in Advanced,
    Ahmed,

    To add to Scott's post.  Option 60 would be useful if you needed to put certain types of AP on specific controllers.  Otherwise, no real need to use it for the most part.
    Though, I do recall an issue a few years ago that some windows machines had issues getting DHCP if option 43 is being returned.
    Now, on an IOS switch, you can only configure one option 60 per DHCP scope
    HTH,
    Steve
    Please remember to rate useful posts, and mark questions as answered

  • Wat should be the regular expression for string MT940_UB_*.txt to be used in SFTP sender channel in PI 7.31 ??

    Hi All,
    What should be the regular expression for string MT940_UB_*.txt and MT940_MB_*.txt to be used as filename inSFTP sender channel in PI 7.31 ??
    If any one has any idea on this please let me know.
    Thanks
    Neha

    Hi All,
    None of the file names suggested is working.
    I have tried using - MT940_MB_*\.txt , MT940_MB_*.*txt , MT940*.txt
    None of them is able to pick this filename - MT940_MB_20142204060823_1.txt
    Currently I am using generic regular expression which picks all .txt files. - ([^\s]+(\.(txt))$)
    Let me know ur suggestion on this.
    Thanks
    Neha Verma

  • Using bytes or chars for String phonetic algorithm?

    Hi all. I'm working on a phonetic algorithm, much like Soundex.
    Basically the program receives a String, read it either char by char or by chunks of chars, and returns its phonetic version.
    The question is which method is better work on this, treating each String "letter" as a char or as a byte?
    For example, let's assume one of the rules is to remove every repeated character (e.g., "jagged" becomes "jaged"). Currently this is done as follows:
    public final String removeRepeated(String s){
                    char[] schar=s.toCharArray();
              StringBuffer sb =new StringBuffer();
              int lastIndex=s.length()-1;
              for(int i=0;i<lastIndex;i++){
                   if(schar!=schar[i+1]){
                        sb.append(schar[++i]);//due to increment it wont work for 3+ repetions e.g. jaggged -> jagged
              sb.append(schar[lastIndex]);
              return sb.toString();
    Would there be any improvement in this computation:public final String removeRepeated(String s){
              byte[] sbyte=s.getBytes();
              int lastIndex=s.length()-1;
              for(int i=0;i<lastIndex;i++){
                   if(sbyte[i]==sbyte[i+1]){
                        sbyte[++i]=32; //the " " String
              return new String(sbyte).replace(" ","");
    Well, in case there isn't much improvement from the short(16-bit) to the byte (8-bit) computation, I would very much appreciate if anyone could explain to me how a 32-bit/64-bit processor handles such kind of data so that it makes no difference to work with either short/byte in this case.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    You may already know that getBytes() converts the string to a byte array according to the system default encoding, so the result can be different depending on which platform you're running the code on. If the encoding happens to be UTF-8, a single character can be converted to a sequence of up to four bytes. You can specify a single-byte encoding like ISO-8859-1 using the getBytes(String) method, but then you're limited to using characters that can be handled by that encoding. As long as the text contains only ASCII characters you can get away with treating bytes and characters as interchangeable, but it could turn around and bite you later.
    Your purpose in using bytes is to make the program more efficient, but I don't think it's worth the effort. First, you'll be constantly converting between {color:#000080}byte{color}s and {color:#000080}char{color}s, which will wipe out much of your efficiency gain. Second, when you do comparisons and arithmetic on {color:#000080}byte{color}s, they tend to get promoted to {color:#000080}int{color}s, so you'll be constantly casting them back to {color:#000080}byte{color}s, but you have to watch for values changing as the JVM tries to preserve their signs.
    In short, converting the text to bytes is not going to do anywhere near enough good to justify the extra work it entails. I recommend you leave the text in the form of {color:#000080}char{color}s and concentrate on minimizing the number of passes you make over it.

  • Substring for Strings, what do I use for a int variable???

    Hi!
    substring for Strings...
    String s1 = p.substring(1,2);
    but what do I use for a int variable?
    int i1 = integ."???????"(1,2);
    /Henrik

    why, you use maths of course!!
    or if you're not up to that, try this:
    int x = 931;
    String s = x+"";
    String res = s.substring(1, 2);
    and of course set it back to an int
    with Integer.parseInt(res);

  • "buffer too small for string or missing null byte" inserting CR in excel

    I have created a Crystal Report based on below stored procedure.
    DELIMITER $$
    DROP PROCEDURE IF EXISTS `ww_test`.`PRD_Data_sp` $$
    CREATE PROCEDURE `ww_test`.`PRD_Data_sp` (in cyear int, in cmonth int, in groupby varchar(20), in Inv_type varchar(4))
    BEGIN
      select
              CASE WHEN groupby='Date' THEN  (p.FKDAT)
                   WHEN groupby='SalesOrg' THEN  CONCAT(p.VKORG,'_',p.VTWEG)
              END ,
              sum(p.QTYSAM),
              sum(p.CASESSOLD),
              sum(p.SOLDDOL)
              from ww_test.prd_data p
              where (month(p.FKDAT)=cmonth and year(p.FKDAT)=cyear) and
                     ((p.FKART) is null or not(p.FKART in ("FAZ","ZMBB","FAS",Inv_Type))) and
                     ((p.AUART) is null or not(p.AUART in ("ZMBB")))
              Group by
                  CASE WHEN groupby='Date' THEN  (p.FKDAT)
                       WHEN groupby='SalesOrg' THEN  CONCAT(p.VKORG,'_',p.VTWEG)
                  END
              Order by
                  CASE WHEN groupby='Date' THEN  (p.FKDAT)
                       WHEN groupby='SalesOrg' THEN  CONCAT(p.VKORG,'_',p.VTWEG)
                  END;
    END $$
    DELIMITER ;
    I have used Add Command to create report based on this.
    call ww_test.prd_data_sp({?Year},{?Month},{?GroupBy},{?InvType});
    I am able to refresh the report in crystal and as well in Infoview without any problem.
    But when i try to insert this report in Excel using Live Office it gives me error. I able to insert other crystal reports without any problem.
    An error occurred while opening the report. The report does not exist; you have insufficient rights to open the report; or you cannot make a connection to the BusinessObjects Web Service. (LO 02010)
    Failed to open report (LO 26619)
    Cannot open report document 
    Buffer too small for string or missing null byte.
    can anyone suggest where i am going wrong? Any input is appreciated.
    Crystal Reports 2008
    Live Office XI 3.1
    BOEdge XI 3.1
    Xcelsius 2008
    Thanks ,
    Madhavi

    With the CurrentValue method
    Crpt.ParamFields[3].CurrentValue := memo1.Text;
    Is there another solution ?

  • Concat two string without 'losing' memory...

    Hi,
    I am using this code
    public class Test{
         Test(){
              String s = "a";
              for (int i = 0 ; i < 23 ; i++)
                   s = s.concat(s);
                   //s += s;
              System.out.println(s.length() / 1048576);
    System.out.println("MAX MEMORY = " + Runtime.getRuntime().maxMemory() / 1048576 + "MB");
    System.out.println("TOTAL MEMORY = " + Runtime.getRuntime().totalMemory() / 1048576 + "MB");
    System.out.println("FREE MEMORY = " + Runtime.getRuntime().freeMemory() / 1048576 + "MB");
                   //s += s;
                   s = s.concat(s);
              System.out.println(s.length() / 1048576);
    System.out.println("MAX MEMORY = " + Runtime.getRuntime().maxMemory() / 1048576 + "MB");
    System.out.println("TOTAL MEMORY = " + Runtime.getRuntime().totalMemory() / 1048576 + "MB");
    System.out.println("FREE MEMORY = " + Runtime.getRuntime().freeMemory() / 1048576 + "MB");
         public static void main(String args[]){
              Test t = new Test();
    }I get on console this
    8
    MAX MEMORY = 508MB
    TOTAL MEMORY = 508MB
    FREE MEMORY = 483MB
    16
    MAX MEMORY = 508MB
    TOTAL MEMORY = 508MB
    FREE MEMORY = 451MB
    It took 32MB which is very much. Can I do something, and what I should do, to take less memory? It is logical if I had string of size 8 MB and to the same string I add 8 MB, to be FREE MEMORY 8 MB less then before, but not 32 MB.
    Thank you.

    Don't use the method concat on strings. Use a
    StringBuffer or StringBuilder instead. If I instead
    String s = "a"; put
    StringBuffer s = new StringBuffer();
    s.append("a");and instead
    s = s.concat(s);put
    s.append(s.toString());
    FREE MEMORY becomes 472MB and 428MB, before was 483MB and 451MB.
    >
    Do also note that the GC executes when it needs to,
    and the memory that has been allocated for the old
    strings can be collected later on.And my aplication breaks :(
    >
    Kaj

  • I use Outlook for my email on the Safari web browser, and about 90% of the time when I want to attach a pdf or jpg file the email message will crash.

    I use Outlook for my email on the Safari web browser, and about 90% of the time when I want to attach a pdf or jpg file it fails and about 50% of the time when I want to send a standard text massage it will also fail and the email massage crashes. The only way I can get my Outlook to work is if I switch to Firefox web browser. I would rather not switch to a new web browser if I don't have to.
    It seems like what ever the problem is that its related the Safari web browser, because it works fine on the Firefox web browser.
    I think its some kind of plug-in failure because it giving me a LOC ERROR:
    LOC ERROR: Unable to locate localized string for resource ID 5007.
    How can I fix this Plug-in?
    And, yes my softwer is conpletly updated…

    That's an Outlook issue. You'll probably get better responses posting on the Office for Mac forums.

Maybe you are looking for

  • Data from different databases in the same report.

    Hi Everyone, I am trying to build a reconciliation report in which I need to show the data from the source and target, side by side. Source and target are both different databases, although being oracle only Whenever a new data model is created, it g

  • Oracle Sql Developer Installation

    Hi Guys, I will be using oracle sql developr at my place and currently installed it at my personal pc.I am very new to the Oracle Sql Developer. I am not able to connect to the Oracle sql Developer.I have Oracle 9i db and oracle forms 10G running and

  • Generic DataSource using function module

    Hello experts, I created a generic dataSource using copy of function module RSAX_BIW_GET_DATA. It is syntactilly correct. But when I execute  and debug associated generic DataSource in RSA3, this generic function module could not identify DataSource(

  • How to change the account group of a customer master?

    Would like to change Ship-to's to Sold-to's.  I know the transaction XD07, but when trying to promote a SH to SP, I receive the error The planned change is not allowed as the following field groups would be masked by the new account group. Below the

  • Unable to download emails. No signon.remember line in prefs.js file

    i have 4 email accounts in mozilla thunderbird. unable to download or send emails. looks as through the passwords for all 4 accounts are deleted. Could not locate user_pref("signon.rememberSignons", false); in the prefs.js file.