string-concatenation

Compilation of string literals

给你一囗甜甜゛ 提交于 2019-12-01 05:05:47
问题 Why can two string literals separated by a space, tab or "\n" be compiled without an error? int main() { char * a = "aaaa" "bbbb"; } "aaaa" is a char* "bbbb" is a char* There is no specific concatenation rule to process two string literals. And obviously the following code gives an error during compilation: #include <iostream> int main() { char * a = "aaaa"; char * b = "bbbb"; std::cout << a b; } Is this concatenation common to all compilers? Where is the null termination of "aaaa"? Is

Lua: attempt to perform arithmetic on a string value

偶尔善良 提交于 2019-12-01 04:49:35
I'm trying to add a string to a returned value in lua: local function func(str) return (str+"_something") end print(func("ABC")) and I'm getting an error: "attempt to perform arithmetic on local 'str' (a string value)" or this error (in my original program): @user_script:1: user_script:1: attempt to perform arithmetic on a string value I tried to use tosring(str)+"_something" but didn't help... so how to Concatenate a string in Lua ? Aviram Net see "Concatenation" in this link : http://lua-users.org/wiki/StringsTutorial The solution is to use the .. , as in example: local function func(str)

String.Join performance issue in C#

£可爱£侵袭症+ 提交于 2019-12-01 02:45:09
I've been researching a question that was presented to me: How to write a function that takes a string as input and returns a string with spaces between the characters. The function is to be written to optimize performance when it is called thousands of times per second. I know that .net has a function called String.Join , to which I may pass in the space character as a separator along with the original string. Barring the use of String.Join , I can use the StringBuilder class to append spaces after each character. Another way to accomplish this task is to declare a character array with 2*n-1

Slow string concatenation over large input

自古美人都是妖i 提交于 2019-12-01 02:17:57
问题 I've written an n-ary tree ADT which works fine. However, I need to store its serialization in a variable a calling class. eg. DomTree<String> a = Data.createTreeInstance("very_large_file.xml"); String x = a.toString(); I've written method which serves the purpose exactly how I need it, but on very large inputs it takes forever (20mins on a 100MB xml file) - I have timed the methods and building the tree from the xml file is quick, but calling toString() as shown above is very slow. @Override

Lua: attempt to perform arithmetic on a string value

假装没事ソ 提交于 2019-12-01 02:15:22
问题 I'm trying to add a string to a returned value in lua: local function func(str) return (str+"_something") end print(func("ABC")) and I'm getting an error: "attempt to perform arithmetic on local 'str' (a string value)" or this error (in my original program): @user_script:1: user_script:1: attempt to perform arithmetic on a string value I tried to use tosring(str)+"_something" but didn't help... so how to Concatenate a string in Lua ? 回答1: see "Concatenation" in this link: http://lua-users.org

How to concatenate strings in c++?

痞子三分冷 提交于 2019-12-01 01:12:44
string degreesToDMS(double angle) { int intpart = 0; int intpart2 = 0; int intpart3 = 0; return floor(angle) << "\xb0" << modf(angle, &intpart)*60 << "'" << modf(modf(angle, &intpart2), &intpart3)*60 << "\""; } This function takes in an angle in degrees and outputs a latitude. I am getting errors on the return statement. How do I properly concatenate different data types to a string in C++? If you want to use the streaming operators then use a std::stringstream, like this:- string degreesToDMS(double angle) { int intpart = 0; int intpart2 = 0; int intpart3 = 0; stringstream ss; ss << floor

When is StringBuffer/StringBuilder not implicitly used by the compiler?

半城伤御伤魂 提交于 2019-11-30 23:53:34
问题 I've heard that the compiler (or was it the JVM?) will automatically use a StringBuilder for some string concatenation. When is the right time to explicitly declare one? I don't need a StringBuffer for being thread-safe. Thanks. 回答1: The compiler will use it automatically for any string concatenation using "+". You'd usually use it explicitly if you wanted to concatenate in a loop. For example: StringBuilder builder = new StringBuilder(); for (String name : names) { builder.append(name);

String concatenation with ASP.NET MVC3 Razor

笑着哭i 提交于 2019-11-30 22:25:00
问题 i'm trying to concatenate a string in asp.net mvc 3 razor and i'm getting a little sintax problem with my cshtml. i what to generate an id for my checkboxes on a foreach statement, and my checkboxes should start with "chk" and what to cancatenate a fieldon the ID, something like that: <input type="checkbox" id="chk+@obj.field" /> but or exampple the result for id attribute is: id="chk+8" how can i just get a result for something like "chk8"? 回答1: Just put your variable next to prefix: <input

Include a variable inside a NSString?

允我心安 提交于 2019-11-30 22:19:19
This works fine, we all know that: NSString *textoutput = @"Hello"; outLabel.text = textoutput; However, what if you want to include a variable inside that NSString statement like the following: NSString *textoutput =@"Hello" Variable; In C++ I know when I cout something and I wanted to include a variable all I did was soemthing like this: cout << "Hello" << variableName << endl; So I'm trying to accomplish that with Objective-C but I don't see how. You can do some fancy formatting using the following function: NSString *textoutput = [NSString stringWithFormat:@"Hello %@", variable]; Note that

How to concatenate strings in c++?

删除回忆录丶 提交于 2019-11-30 21:14:01
问题 string degreesToDMS(double angle) { int intpart = 0; int intpart2 = 0; int intpart3 = 0; return floor(angle) << "\xb0" << modf(angle, &intpart)*60 << "'" << modf(modf(angle, &intpart2), &intpart3)*60 << "\""; } This function takes in an angle in degrees and outputs a latitude. I am getting errors on the return statement. How do I properly concatenate different data types to a string in C++? 回答1: If you want to use the streaming operators then use a std::stringstream, like this:- string