Search Results

Search found 300 results on 12 pages for 'concatenation'.

Page 1/12 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Help in debugging the string concatenation code

    - by mithun1538
    I have a code to concatenate strings. However, for some reason, the final string is not a combination of the required strings. Consider the following code : //cusEmail is of type String[] String toList = ""; for(i=0; i < cusEmail.length - 1; i++) { toList.concat(cusEmail[i]); toList.concat("; "); System.out.println(cusEmail[i]); } toList.concat(cusEmail[i]); System.out.println(toList); The first sout statement displays the strings in cusEmail[i] correctly. However, once concatenated, the second sout displays a blank / empty. Any reason for this? Am i concatenating it correctly?

    Read the article

  • Concatenation Operator

    - by Chaitanya
    This might be a silly question but it struck me, and here i ask. <?php $x="Hi"; $y=" There"; $z = $x.$y; $a = "$x$y"; echo "$z"."<br />"."$a"; ?> $z uses the traditional concatenation operator provided by php and concatenates, conversely $a doesn't, My questions: by not using the concatenation operator, does it effect the performance? If it doesn't why at all have the concatenation operator. Why have 2 modes of implementation when one does the work?

    Read the article

  • Concatenation Operator - PHP

    - by Chaitanya
    This might be a silly question but it struck me, and here i ask. <?php $x="Hi"; $y=" There"; $z = $x.$y; $a = "$x$y"; echo "$z"."<br />"."$a"; ?> $z uses the traditional concatenation operator provided by php and concatenates, conversely $a doesn't, My questions: a. by not using the concatenation operator, does it effect the performance? b. If it doesn't why at all have the concatenation operator. c. Why have 2 modes of implementation when one does the work?

    Read the article

  • Database-independant SQL String Concatenation in Rails

    - by Craig Walker
    I want to do a database-side string concatenation in a Rails query, and do it in database-independent way. SQL-92 specifies double-bar (||) as the concatenation operator. Unfortunately it looks like MS SQL Server doesn't support it; it uses + instead. I'm guessing that Rails' SQL grammar abstraction has solved the db-specific operator problem already. If it does exist, how do I use it?

    Read the article

  • C++ Preprocessor string literal concatenation

    - by ezpz
    I found this regarding how the C preprocessor should handle string literal concatenation (phase 6). However, I can not find anything regarding how this is handled in C++ (does C++ use the C preprocessor?). The reason I ask is that I have the following: const char * Foo::encoding = "\0" "1234567890\0abcdefg"; where encoding is a static member of class Foo. Without the availability of concatenation I wouldnt be able to write that sequence of characters like that. const char * Foo::encoding = "\01234567890\0abcdefg"; Is something entirely different due to the way \012 is interpreted. I dont have access to multiple platforms and I'm curious how confident I should be that the above is always handled correctly - i.e. I will always get { 0, '1', '2', '3', ... }

    Read the article

  • Does string concatenation use StringBuilder internally?

    - by JamesBrownIsDead
    Three of my coworkers just told me that there's no reason to use a StringBuilder in place of concatenation using the + operator. In other words, this is fine to do with a bunch of strings: myString1 + myString2 + myString3 + myString4 + mySt... The rationale that they used was that since .NET 2, the C# compiler will build the same IL if you use the + operator as if you used a StringBuilder. This is news to me. Are they correct?

    Read the article

  • String concatenation: Final string value does not equal to the latest value

    - by Pan Pizza
    I have a simple question about string concatenation. Following is the code. I want to ask why s6 = "abcde" and not "akcde"? I have change the s2 value to "k". Public Class Form1 Public s1 As String = "a" Public s2 As String = "b" Public s3 As String = "c" Public s4 As String = "d" Public s5 As String = "e" Public s6 As String = "" Public s7 As String = "k" Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click s6 = s1 & s2 & s3 & s4 & s5 s2 = s7 MessageBox.Show(s6) 's6 = abcde End Sub End Class

    Read the article

  • T-SQL While Loop and concatenation

    - by JustinT
    I have a SQL query that is supposed to pull out a record and concat each to a string, then output that string. The important part of the query is below. DECLARE @counter int; SET @counter = 1; DECLARE @tempID varchar(50); SET @tempID = ''; DECLARE @tempCat varchar(255); SET @tempCat = ''; DECLARE @tempCatString varchar(5000); SET @tempCatString = ''; WHILE @counter <= @tempCount BEGIN SET @tempID = ( SELECT [Val] FROM #vals WHERE [ID] = @counter); SET @tempCat = (SELECT [Description] FROM [Categories] WHERE [ID] = @tempID); print @tempCat; SET @tempCatString = @tempCatString + '<br/>' + @tempCat; SET @counter = @counter + 1; END When the script runs, @tempCatString outputs as null while @tempCat always outputs correctly. Is there some reason that concatenation won't work inside a While loop? That seems wrong, since incrementing @counter works perfectly. So is there something else I'm missing?

    Read the article

  • Speed vs security vs compatibility over methods to do string concatenation in Python

    - by Cawas
    Similar questions have been brought (good speed comparison there) on this same subject. Hopefully this question is different and updated to Python 2.6 and 3.0. So far I believe the faster and most compatible method (among different Python versions) is the plain simple + sign: text = "whatever" + " you " + SAY But I keep hearing and reading it's not secure and / or advisable. I'm not even sure how many methods are there to manipulate strings! I could count only about 4: There's interpolation and all its sub-options such as % and format and then there's the simple ones, join and +. Finally, the new approach to string formatting, which is with format, is certainly not good for backwards compatibility at same time making % not good for forward compatibility. But should it be used for every string manipulation, including every concatenation, whenever we restrict ourselves to 3.x only? Well, maybe this is more of a wiki than a question, but I do wish to have an answer on which is the proper usage of each string manipulation method. And which one could be generally used with each focus in mind (best all around for compatibility, for speed and for security). Thanks.

    Read the article

  • When should I use String.Format or String.Concat instead of the concatenation operator?

    - by Kramii
    In C# it is possible to concatenate strings in several different ways: Using the concatenation operator: var newString = "The answer is '" + value + "'."; Using String.Format: var newString = String.Format("The answer is '{0}'.", value); Using String.Concat: var newString = String.Concat("The answer is '", value, "'."); What are the advantages / disadvantages of each of these methods? When should I prefer one over the others? The question arises because of a debate between developers. One never uses String.Format for concatenation - he argues that this is for formatting strings, not for concatenation, and that is is always unreadable because the items in the string are expressed in the wrong order. The other frequently uses String.Format for concatenation, because he thinks it makes the code easier to read, especially where there are several sets of quotes involved. Both these developers also use the concatenation operator and String.Builder, too.

    Read the article

  • vb.net string concatenation string + function output + string = string + function output and no more

    - by Barfieldmv
    The following output produces a string with no closing xml tag. m_rFlight.Layout = m_rFlight.Layout + "<G3Grid:Spots>" + Me.gvwSpots.LayoutToString() + "</G3Grid:Spots>" This following code works correctly m_rFlight.Layout = m_rFlight.Layout + "<G3Grid:Spots>" + Me.gvwSpots.LayoutToString() m_rFlight.Layout = m_rFlight.Layout + "</G3Grid:Spots>" 'add closing tag What's going on here, what's the reason the first example isnt working and the second is? The gvwSpots.LayoutToString() function returns a string.

    Read the article

  • Concatenation of fields in different rows

    - by spender
    I'm stuck on an aggregation problem that I can't get to the bottom of. I have some data which is best summarized as follows id |phraseId|seqNum|word ========================= 1 |1 |1 |hello 2 |1 |2 |world 3 |2 |1 |black 4 |2 |2 |and 5 |2 |3 |white I'd like a query that gives back the following data: phraseId|completePhrase ======================== 1 |hello world 2 |black and white Anyone?

    Read the article

  • Path String Concatenation Question in C#.

    - by Nano HE
    Hello. I want to output D:\Learning\CS\Resource\Tutorial\C#LangTutorial But can't work. Compiler error error CS0165: Use of unassigned local variable 'StrPathHead Please give me some advice about how to correct my code or other better solution for my case. Thank you. static void Main(string[] args) { string path = "D:\\Learning\\CS\\Resource\\Book\\C#InDeepth"; int n = 0; string[] words = path.Split('\\'); foreach (string word in words) { string StrPathHead; string StrPath; Console.WriteLine(word); if (word == "Resource") { StrPath = StrPathHead + word + "\\Tutorial\\C#LangTutorial"; } else { StrPathHead += words[n++] + "\\"; } } }

    Read the article

  • Array Concatenation in C#

    - by Betamoo
    1- How to smartly initialize an Array with 2 (or more) other arrays in C#? double[] d1=new double[5]; double[] d2=new double[3]; double[] dTotal=new double[8];// I need this to be {d1 then d2} 2- Another question: How to concatenate C# arrays efficiently? Thanks

    Read the article

  • String concatenation produces incorrect output in Python?

    - by Brian
    I have this code: filenames=["file1","FILE2","file3","fiLe4"] def alignfilenames(): #build a string that can be used to add labels to the R variables. #format goal: suffixes=c(".fileA",".fileB") filestring='suffixes=c(".' for filename in filenames: filestring=filestring+str(filename)+'",".' print filestring[:-3] #now delete the extra characters filestring=filestring[-1:-4] filestring=filestring+')' print "New String" print str(filestring) alignfilenames() I'm trying to get the string variable to look like this format: suffixes=c(".fileA",".fileB".....) but adding on the final parenthesis is not working. When I run this code as is, I get: suffixes=c(".file1",".FILE2",".file3",".fiLe4" New String ) Any idea what's going on or how to fix it?

    Read the article

  • Prolog term concatenation

    - by d0pe
    Hi, I'm trying to format a result from a program but getting an hard time. I wanted to give something like this as result: Res = do(paint(x) do(clean(a), do(repair(b) , initialState))) basically, I want to concatenate successive terms to initialState atom but, it doesn't work with atom_concat since the other terms to concatenate aren't atoms and also I wanted to add the ) everytime I pass through the "do" function. So it would be something like: Res = initialState. When do function was called, I would have a function like concatenateTerm(Pred, Res, Res). Pred beeing repair(b) for instance and obtain the result: res = do(repair(b), initialState). Is this possible to be done? Thanks

    Read the article

  • C#: String Concatenation vs Format vs StringBuilder

    - by James Michael Hare
    I was looking through my groups’ C# coding standards the other day and there were a couple of legacy items in there that caught my eye.  They had been passed down from committee to committee so many times that no one even thought to second guess and try them for a long time.  It’s yet another example of how micro-optimizations can often get the best of us and cause us to write code that is not as maintainable as it could be for the sake of squeezing an extra ounce of performance out of our software. So the two standards in question were these, in paraphrase: Prefer StringBuilder or string.Format() to string concatenation. Prefer string.Equals() with case-insensitive option to string.ToUpper().Equals(). Now some of you may already know what my results are going to show, as these items have been compared before on many blogs, but I think it’s always worth repeating and trying these yourself.  So let’s dig in. The first test was a pretty standard one.  When concattenating strings, what is the best choice: StringBuilder, string concattenation, or string.Format()? So before we being I read in a number of iterations from the console and a length of each string to generate.  Then I generate that many random strings of the given length and an array to hold the results.  Why am I so keen to keep the results?  Because I want to be able to snapshot the memory and don’t want garbage collection to collect the strings, hence the array to keep hold of them.  I also didn’t want the random strings to be part of the allocation, so I pre-allocate them and the array up front before the snapshot.  So in the code snippets below: num – Number of iterations. strings – Array of randomly generated strings. results – Array to hold the results of the concatenation tests. timer – A System.Diagnostics.Stopwatch() instance to time code execution. start – Beginning memory size. stop – Ending memory size. after – Memory size after final GC. So first, let’s look at the concatenation loop: 1: // build num strings using concattenation. 2: for (int i = 0; i < num; i++) 3: { 4: results[i] = "This is test #" + i + " with a result of " + strings[i]; 5: } Pretty standard, right?  Next for string.Format(): 1: // build strings using string.Format() 2: for (int i = 0; i < num; i++) 3: { 4: results[i] = string.Format("This is test #{0} with a result of {1}", i, strings[i]); 5: }   Finally, StringBuilder: 1: // build strings using StringBuilder 2: for (int i = 0; i < num; i++) 3: { 4: var builder = new StringBuilder(); 5: builder.Append("This is test #"); 6: builder.Append(i); 7: builder.Append(" with a result of "); 8: builder.Append(strings[i]); 9: results[i] = builder.ToString(); 10: } So I take each of these loops, and time them by using a block like this: 1: // get the total amount of memory used, true tells it to run GC first. 2: start = System.GC.GetTotalMemory(true); 3:  4: // restart the timer 5: timer.Reset(); 6: timer.Start(); 7:  8: // *** code to time and measure goes here. *** 9:  10: // get the current amount of memory, stop the timer, then get memory after GC. 11: stop = System.GC.GetTotalMemory(false); 12: timer.Stop(); 13: other = System.GC.GetTotalMemory(true); So let’s look at what happens when I run each of these blocks through the timer and memory check at 500,000 iterations: 1: Operator + - Time: 547, Memory: 56104540/55595960 - 500000 2: string.Format() - Time: 749, Memory: 57295812/55595960 - 500000 3: StringBuilder - Time: 608, Memory: 55312888/55595960 – 500000   Egad!  string.Format brings up the rear and + triumphs, well, at least in terms of speed.  The concat burns more memory than StringBuilder but less than string.Format().  This shows two main things: StringBuilder is not always the panacea many think it is. The difference between any of the three is miniscule! The second point is extremely important!  You will often here people who will grasp at results and say, “look, operator + is 10% faster than StringBuilder so always use StringBuilder.”  Statements like this are a disservice and often misleading.  For example, if I had a good guess at what the size of the string would be, I could have preallocated my StringBuffer like so:   1: for (int i = 0; i < num; i++) 2: { 3: // pre-declare StringBuilder to have 100 char buffer. 4: var builder = new StringBuilder(100); 5: builder.Append("This is test #"); 6: builder.Append(i); 7: builder.Append(" with a result of "); 8: builder.Append(strings[i]); 9: results[i] = builder.ToString(); 10: }   Now let’s look at the times: 1: Operator + - Time: 551, Memory: 56104412/55595960 - 500000 2: string.Format() - Time: 753, Memory: 57296484/55595960 - 500000 3: StringBuilder - Time: 525, Memory: 59779156/55595960 - 500000   Whoa!  All of the sudden StringBuilder is back on top again!  But notice, it takes more memory now.  This makes perfect sense if you examine the IL behind the scenes.  Whenever you do a string concat (+) in your code, it examines the lengths of the arguments and creates a StringBuilder behind the scenes of the appropriate size for you. But even IF we know the approximate size of our StringBuilder, look how much less readable it is!  That’s why I feel you should always take into account both readability and performance.  After all, consider all these timings are over 500,000 iterations.   That’s at best  0.0004 ms difference per call which is neglidgable at best.  The key is to pick the best tool for the job.  What do I mean?  Consider these awesome words of wisdom: Concatenate (+) is best at concatenating.  StringBuilder is best when you need to building. Format is best at formatting. Totally Earth-shattering, right!  But if you consider it carefully, it actually has a lot of beauty in it’s simplicity.  Remember, there is no magic bullet.  If one of these always beat the others we’d only have one and not three choices. The fact is, the concattenation operator (+) has been optimized for speed and looks the cleanest for joining together a known set of strings in the simplest manner possible. StringBuilder, on the other hand, excels when you need to build a string of inderterminant length.  Use it in those times when you are looping till you hit a stop condition and building a result and it won’t steer you wrong. String.Format seems to be the looser from the stats, but consider which of these is more readable.  Yes, ignore the fact that you could do this with ToString() on a DateTime.  1: // build a date via concatenation 2: var date1 = (month < 10 ? string.Empty : "0") + month + '/' 3: + (day < 10 ? string.Empty : "0") + '/' + year; 4:  5: // build a date via string builder 6: var builder = new StringBuilder(10); 7: if (month < 10) builder.Append('0'); 8: builder.Append(month); 9: builder.Append('/'); 10: if (day < 10) builder.Append('0'); 11: builder.Append(day); 12: builder.Append('/'); 13: builder.Append(year); 14: var date2 = builder.ToString(); 15:  16: // build a date via string.Format 17: var date3 = string.Format("{0:00}/{1:00}/{2:0000}", month, day, year); 18:  So the strength in string.Format is that it makes constructing a formatted string easy to read.  Yes, it’s slower, but look at how much more elegant it is to do zero-padding and anything else string.Format does. So my lesson is, don’t look for the silver bullet!  Choose the best tool.  Micro-optimization almost always bites you in the end because you’re sacrificing readability for performance, which is almost exactly the wrong choice 90% of the time. I love the rules of optimization.  They’ve been stated before in many forms, but here’s how I always remember them: For Beginners: Do not optimize. For Experts: Do not optimize yet. It’s so true.  Most of the time on today’s modern hardware, a micro-second optimization at the sake of readability will net you nothing because it won’t be your bottleneck.  Code for readability, choose the best tool for the job which will usually be the most readable and maintainable as well.  Then, and only then, if you need that extra performance boost after profiling your code and exhausting all other options… then you can start to think about optimizing.

    Read the article

  • Showplan Operator of the Week - Concatenation

    Fabiano continues in his mission to describe, one week at a time, all the major Showplan Operators used by SQL Server's Query Optimiser to build the Query Plan. This week he gets the Concatenation operator ....Did you know that DotNetSlackers also publishes .net articles written by top known .net Authors? We already have over 80 articles in several categories including Silverlight. Take a look: here.

    Read the article

  • Using SQL Server Concatenation Efficiently

    This article shares some tips on using concatenation efficiently for application development, pointing out some things that we must consider and look at when concatenating values or fields in our queries or stored procedures. NEW! Never waste another weekend deployingDeploy SQL Server changes and ASP .NET applications fast, frequently, and without fuss, using Deployment Manager, the new tool from Red Gate. Try it now.

    Read the article

  • What causes exception in string.concat

    - by Budda
    Here are few classes: public class MyItem : ParamOut { public string Code { get { return _quoteCode; } } public InnerItem[] Skus { get { return _skus; } } public PriceSummary Price { get { return _price; } } public override string ToString() { return string.Concat("Code=", Code, "; SKUs=[", Skus != null ? "{" + string.Join("},{", Array.ConvertAll(Skus, item => item.ToString())) + "}" : "", "]" , "; Price={", Price.ToString(), "}", base.ToString() ); } ... } public abstract class ParamOut { public override string ToString() { return null; } public string ErrorMessage { get; set; } } Here is calling functionality: { MyItem item = new MyItem{ ErrorMessage = "Bla-bla-bla" }; string text = item.ToString(); } I am getting NullReference exception inside of 'ToString()' method (each property of item variable is null). Question: Q1. what overload of string.Concat will be called in this case? I have 9 parameters, so I guess one of the following: public static string Concat(params Object[] args) or public static string Concat(params string[] values) But which of them? Q2. Why exception is generated? Shouldn't 'null' be converted into something like 'null' or "" (empty string)? Thanks a lot!

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >