Questions tagged [string-building]

19 questions
39
votes
7 answers

How many String objects would be created when concatenating multiple Strings?

I was asked in an interview about the number of objects that will be created on the given problem: String str1 = "First"; String str2 = "Second"; String str3 = "Third"; String str4 = str1 + str2 + str3; I answered that there would be 6 objects…
6
votes
4 answers

Building a directory string from component parts in C#

If i have lots of directory names either as literal strings or contained in variables, what is the easiest way of combining these to make a complete path? I know of Path.Combine but this only takes 2 string parameters, i need a solution that can…
Gary Willoughby
  • 50,926
  • 41
  • 133
  • 199
4
votes
4 answers

What problem does the StringBuilder solve?

Why would I use a StringBuilder over simply appending strings? For example why implement like: StringBuilder sb = new StringBuilder; sb.Append("A string"); sb.Append("Another string"); over String first = "A string"; first += "Another string"; ?
m.edmondson
  • 30,382
  • 27
  • 123
  • 206
2
votes
9 answers

PHP function to add data to string

My code: $myText = ""; function addText($textString){ $myText .= $textString; } addText("Hello there..."); echo $myText; Expected output: Hello There... $myText was empty. Why does this happen?
Dave
  • 1,076
  • 5
  • 15
  • 30
2
votes
3 answers

Best way to build string avoiding repetition

I have a hard coded string that will be used in a URL and I'm wanting to know is what the best way to build this string without having to repeat the words country, or, and, number? This is a shortened version as there are more countries and numbers…
user3586417
2
votes
1 answer

Building a string in C

This seems like a question that would have been asked before, but I couldn't find it. (If you do, please point me there and close this as a duplicate.) I have C code which works something like this: printf("some characters"); for (; n >= 0; n--) { …
Charles
  • 11,269
  • 13
  • 67
  • 105
2
votes
2 answers

Building an Evironment Variable with SET using a FOR loop in Command Prompt

I am having trouble with the following command prompt commands (in Windows XP). set SOMEVAR= for /F %i in (1 2 3) do set SOMEVAR=%SOMEVAR% "%i" echo %SOMEVAR% I expect it to build the SOMEVAR variable so that it contains each item in…
1
vote
2 answers

String building in C++ exception’s what()

This answer declares a private static ostringstream. Is this thread safe? If two threads throw (and catch, and log what()) the exception at the same time, does this work reliably? If I declare the ostringstream locally, like: virtual const char*…
Matthias Ronge
  • 9,403
  • 7
  • 47
  • 63
1
vote
3 answers

Building a string using ternary operations

I'm trying to build a string using ternary operations and pass it to a cell of an Excel file. Here is my code: ws.Rows[index].Cells[24].Value = i.IliskiliCokluIsler.Count == 0 ? i.IliskiliMahalle.MahalleAdi != null ?…
jason
  • 6,962
  • 36
  • 117
  • 198
1
vote
0 answers

String Building in SQL Server

According to the Microsoft Documentation sp_send_dbmail must be a semicolon delimited list. However, in many of my applications I am unable to guarantee that this list will be clean. I need a robust way for ensuring a syntactically valid list of…
Chiramisu
  • 4,687
  • 7
  • 47
  • 77
1
vote
1 answer

C++: how to output data to multiple .dat files?

I have a research project I'm working on. I am a beginner in C++ and programming in general. I have already made a program that generates interacting particles that move on continuous space as time progresses. The only things my program outputs are…
Dima1982
  • 189
  • 3
  • 18
0
votes
3 answers

Building a query string based on variable values. Where is the mistake?

I am trying to create a query string based on GET values passed to common vars: if isset, gTipo = $_GET['tipo'] and others like this. So, here is the code that is not working: $sqlLista = 'SELECT * FROM produtos'; if($gTipo <> 0 || $gLinha <>…
0
votes
3 answers

Generating HTML with strings

I am trying to add an image into HTML. Using the following works:  All i want to do is replace the http with a variable so I can call in the website rather than have it be…
0
votes
2 answers

How to perform Split and Stringbuilding in SQL?

I'm a SQL acolyte, spending most of my time in Powershell. So for the purposes of this, I shall express myself thusly. Basically, I have a column of FullName, that contains FirstName LastName, and I want it restructured to LastName, Firstname in a…
user3066571
  • 1,381
  • 4
  • 14
  • 37
0
votes
3 answers

Building a Query From a List of Strings

How would you take an arbitrary list of strings (of the form "%[text]%") and a database column, and turn them into a SQL query that does a LIKE comparison for each string in the list? An example: I have three strings in my list, "%bc%", "%def%" and…
Merus
  • 8,796
  • 5
  • 28
  • 41
1
2