Questions tagged as 'string'

3
answers

Why does Visual Studio suggest simplifying the names? - IDE0001 Name can be simplified

Visual Studio 2013 suggests simplifying names, as you can see below: The suggestion is:    IDE0001 Name can be simplified translating: IDE0001 Name can be simplified Example: var obj = new Object(); //Sugere a simplic...
asked by 11.08.2015 / 15:48
2
answers

How to align strings to use in a listview?

In my Android project I need to create a table with a listview but the data always comes misaligned. I put each record in my database at a position in an array of strings so I can use it in listview . The method I use to try to alig...
asked by 27.01.2014 / 18:01
3
answers

Turn the first letter of a string in uppercase?

Example: I have a string "stack exchange" , how do I transform its first character, getting "Stack exchange" ?     
asked by 24.08.2015 / 01:33
3
answers

How to convert a string to Listint

I have the following variable and would like to convert it to an integer list: string variavel = "1,2,3"; Is there a way to convert it to a list of integers?     
asked by 06.08.2015 / 14:16
5
answers

How to separate "words" in CamelCase in C #?

How can I separate "words" into CamelCase using hyphen for example? With a string: string example = "CamelCase"; // CamelCase para: // Camel-Case and enumerator: enum Example { CamelCase } Example.CamelCase.ToString(); // CamelC...
asked by 24.02.2018 / 15:37
3
answers

___ ___ erkimt Performance: string "concatenated" or all on the same line? ______ qstntxt ___

I have a loop with thousands of results that renders a table. The string is mounted through the StringBuilder in this way (example snippet):

%pre%

Can there be any performance improvement if I put the whole code in one line, as below?

%pre%

And if it were a concatenation, such as the following code?

%pre%

More advanced explanations of how language works are welcome.

    
______ azszpr7738 ___

The best will always be to keep in a String that is unique at compile time rather than at runtime.

And, believe it or not, in C # you can use line breaks in a single String using the character %code% (at) at the beginning of it.

%pre%

Also, according to this topic in SO , if you concatenate String literals in a same command, they will be concatenated at compile time, then it would give the same effect on runtime performance something like:

%pre%

Using %code% to concatenate String literals will decrease program performance, since it will prevent the compiler from optimizing literals.

On the other hand, if the compiler can not know the size of the String at compile time, for example if we concatenate variables, %code% is usually faster than directly concatenating the values. I say "generally" because I do not really know how much the compiler or CPU would be able to optimize certain exceptional cases.

    
______ azszpr7751 ___

In case of substituting multiple calls from %code% to only one, the gain will be minimal.

On one occasion, working with the class %code% , I noticed a great improvement in performance when booting the %code% with a size sufficient to store the entire result. I did this using two routines, one to count the required size, and another to build the string.

To initialize the StringBuilder with a size simply pass an integer in the con- tractor:

%pre%     
______ azszpr21973 ___

It has been properly said that the best way is to use a single %code% in the case presented. It's fast and legible.

But if there is a reason to do sequential concatenation, it can be used without performance problems. It ends up becoming a single %code% at compile time. The only problem is being less readable.

There is optimization of the compiler in many cases. But not at all. If all of the% s sizes involved are not known, there is not so much optimization. In these cases the optimization only transforms the concatenations in the %code% method. It is certainly better because it avoids unnecessary allocations, but the size calculation is still needed.

Although the %code% property is of type %code% , I have doubts if it can be so optimized.

If it is useful a %code% may be appropriate and not have a performance impairment. It may even be faster than a method %code% of %code% . When you know the total size required for all% s of% s in a simple way, possibly as a constant literal, %code% is very fast. Internally %code% uses a %code% so you find that the former is faster that the second one does not make sense. Of course, in cases that have only 4% with% s the concatenation is made simpler without %code% .

But so far little has been added to what has been said in the other answers.

Alternative: Resources

There are cases to make work easier, the text should not be in the code. It should be in an external file, when this is pertinent, or be in Resources . It may be easier to maintain in this and it is very fast in the second case.

For everything there is the best solution applied. This is a case that easier maintenance can be more important than performance. In case of catching the resource the performance will not be much affected either. And even if it is, it will not create problem for the application. This performance concern makes sense for cases of extreme strings manipulations . In the case of file access the performance will obviously be affected by access to mass memory. But it will still not affect the application. Of course this solution should only be chosen when you want to be able to change the text easily after compilation, when you want to give this freedom to the user.

    
___

I have a loop with thousands of results that renders a table. The string is mounted through the StringBuilder in this way (example snippet): ScriptTbody.AppendLine("</select>"); ScriptTbody.AppendLine("<p class=\"valAnoInicio\"><...
asked by 28.02.2014 / 13:21
4
answers

The input string was not in an incorrect format.

Hello, I'm a beginner in programming and I'm trying to show the user how much RAM is being consumed at the moment, I'm using the following code which is not pointing nor an error compiling only when I give Start it says:   An unhandled excepti...
asked by 12.11.2015 / 18:57
2
answers

What two keys mean in JavaScript

I understand the "===" that tests value and type, different from "==" that tests only value, however I did not understand the double key, type: {{alguma_coisa}} , for example in a JavaScript that I own, has something like this: mozL10n.g...
asked by 03.11.2015 / 11:57
4
answers

How to create a variable where access its properties via string?

I would like to access by string the properties of an object: (EXAMPLE 1) var cor = casa["cor"]; var tamanho = casa["tamanho"]; Instead of access like this: (EXAMPLE 2) var cor = casa.cor; var tamanho = casa.tamanho; Creating this wa...
asked by 13.10.2015 / 18:42
2
answers

How to check if the Term is contained in String in PHP?

I need to check if a given tag is within string . I get this string from the database that comes in the form of% com_with% separated by commas without spaces as below: String canais,proteses,implantes Term proteses...
asked by 22.11.2015 / 04:58