473,411 Members | 2,285 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

This code is efficient

Hello, Is this code efficient?

public static string HTML_FASE1_OTROS_GENERAL =
" <table id='tFase1' cellspacing='0' cellpadding='0' width='800' >" +
" <tr>" +
" <td width='15'></td>" +
" <td width='750'><br>" +
.............

Thanks

Dec 19 '05 #1
13 1478
> Hello, Is this code efficient?

public static string HTML_FASE1_OTROS_GENERAL =
" <table id='tFase1' cellspacing='0' cellpadding='0' width='800' >" +
" <tr>" +
" <td width='15'></td>" +
" <td width='750'><br>" +
............
Thanks


no.. you'll want to use a string builder or

public static string HTML_FASE1_OTROS_GENERAL = @" <table id='tFase1' cellspacing='0'
cellpadding='0' width='800' >
<tr>
<td width='15'></td>
<td width='750'><br>" ;

something like that.. that way the you don't create multiple instances of
string.. and waste memory..
Dec 19 '05 #2
Fran,

Unless this changes a good deal, I would make it constant, if not, then
read-only, unless you have a reason you want other people to change it?

You don't have to worry about the multiple strings. The compiler will
reduce that to one string.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"fran" <fr**@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.com...
Hello, Is this code efficient?

public static string HTML_FASE1_OTROS_GENERAL =
" <table id='tFase1' cellspacing='0' cellpadding='0' width='800' >" +
" <tr>" +
" <td width='15'></td>" +
" <td width='750'><br>" +
............

Thanks

Dec 19 '05 #3
It is not inefficient.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"fran" <fr**@discussions.microsoft.com> wrote in message
news:E2**********************************@microsof t.com...
Hello, Is this code efficient?

public static string HTML_FASE1_OTROS_GENERAL =
" <table id='tFase1' cellspacing='0' cellpadding='0' width='800' >" +
" <tr>" +
" <td width='15'></td>" +
" <td width='750'><br>" +
............

Thanks

Dec 19 '05 #4
Kyoung,

But that's not the case here. The compiler is actually going to
concatenate this at compile-time into one string.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Kyong Kwak" <ky*******@nospam.nospam> wrote in message
news:7b**************************@news.microsoft.c om...
Hello, Is this code efficient?

public static string HTML_FASE1_OTROS_GENERAL =
" <table id='tFase1' cellspacing='0' cellpadding='0' width='800' >" +
" <tr>" +
" <td width='15'></td>" +
" <td width='750'><br>" +
............
Thanks


no.. you'll want to use a string builder or

public static string HTML_FASE1_OTROS_GENERAL = @" <table id='tFase1'
cellspacing='0' cellpadding='0' width='800' >
<tr>
<td width='15'></td>
<td width='750'><br>" ;

something like that.. that way the you don't create multiple instances of
string.. and waste memory..

Dec 19 '05 #5
tjb
Kyong Kwak <ky*******@nospam.nospam> wrote:
Hello, Is this code efficient?

public static string HTML_FASE1_OTROS_GENERAL =
" <table id='tFase1' cellspacing='0' cellpadding='0' width='800' >" +
" <tr>" +
" <td width='15'></td>" +
" <td width='750'><br>" +

<snip>
something like that.. that way the you don't create multiple instances of
string.. and waste memory..


No, the OP's code *doesn't* have this problem. See
<http://www.pobox.com/~skeet/csharp/stringbuilder.html>.
Dec 19 '05 #6
On top of what the other posters have pointed out: that the compiler
will build a single string at compile time so there is no run-time
penalty, I should also point out that even if this weren't the case,
concatenating four or five strings like this is still going to be
cheaper than calls to StringBuilder, or the cost will be almost
identical. Personally, I wouldn't get bent out of shape over a few
string concats, especially in something that isn't inside a loop.

Dec 19 '05 #7
"Kevin Spencer" <ke***@DIESPAMMERSDIEtakempis.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
It is not inefficient.


LOL!
Dec 19 '05 #8
A similar question:

I would have to use replace of the String class or the one of the
StringBuilder class to replace 6 or 7 small substrings of a long string?

"fran" wrote:
Hello, Is this code efficient?

public static string HTML_FASE1_OTROS_GENERAL =
" <table id='tFase1' cellspacing='0' cellpadding='0' width='800' >" +
" <tr>" +
" <td width='15'></td>" +
" <td width='750'><br>" +
............

Thanks

Dec 19 '05 #9
Keep in mind that every time you replace a substring in the long
string, you allocate a whole new long string and build the altered
string into it.

Given that, you have to ask yourself two questions:

1. How long is the "long" string? Personally, in this context, I
wouldn't pay much attention unless it's over a couple of hundred
characters, unless...

2. Are you doing this over and over again? In other words, are you
doing this in a loop? If so, then StringBuilder will probably make a
significant difference, unless...

3. Do you need the replacement to be case-insensitive or culturally
aware? StringBuilder's Replace replaces only the exact string you're
searching for, not any variants on case or culture. If you're building
an internationalized application then you may not be able to use the
StringBuilder version.

In all of this, the StringBuilder version won't be much more efficient
unless you set its Capacity property, or supply the capacity as an
"int" on the constructor, something like this:

StringBuilder sb = new StringBuilder(startingString,
startingString.Length * 2);

because if you don't leave ample space for the string to expand (if the
replacement strings are longer than what they're replacing) then
StringBuilder will just waste a bunch of time expanding itself over and
over to accommodate longer and longer strings, and each expansion is a
copy, just like String.Replace.

So, if you're doing this once when your program starts up, and the
string in question is 100 characters or something like that, don't
worry about it. I would just use
String.Replace().Replace().Replace()...

If you're doing this in a loop or the string is very long (1000
characters or more) then I'd use StringBuilder, but only if I were sure
that my application would never need to worry about international /
case concerns.

Dec 19 '05 #10
> no.. you'll want to use a string builder or

Not correct. If the concatenation occurs in the same statement, multiple
string instances are not created.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
You can lead a fish to a bicycle,
but it takes a very long time,
and the bicycle has to *want* to change.

"Kyong Kwak" <ky*******@nospam.nospam> wrote in message
news:7b**************************@news.microsoft.c om...
Hello, Is this code efficient?

public static string HTML_FASE1_OTROS_GENERAL =
" <table id='tFase1' cellspacing='0' cellpadding='0' width='800' >" +
" <tr>" +
" <td width='15'></td>" +
" <td width='750'><br>" +
............
Thanks


no.. you'll want to use a string builder or

public static string HTML_FASE1_OTROS_GENERAL = @" <table id='tFase1'
cellspacing='0' cellpadding='0' width='800' >
<tr>
<td width='15'></td>
<td width='750'><br>" ;

something like that.. that way the you don't create multiple instances of
string.. and waste memory..

Dec 19 '05 #11
> Given that, you have to ask yourself *two* questions:
1.
2.
3.


Ah, yes. There are three kinds of people in the world: those who can do
math, and those who can't. I fit into the third group. :-)

Dec 19 '05 #12
"Bruce Wood" <br*******@canada.com> wrote in news:1135021132.786528.63550
@g49g2000cwa.googlegroups.com:
Ah, yes. There are three kinds of people in the world: those who can do
math, and those who can't. I fit into the third group. :-)


Actually there are 10 kinds of people. Those who understand binary and
those who don't. ;)

-mdb
Dec 19 '05 #13

"Michael Bray" <mbray@makeDIntoDot_ctiusaDcom> wrote in message
news:Xn****************************@207.46.248.16. ..
"Bruce Wood" <br*******@canada.com> wrote in news:1135021132.786528.63550
@g49g2000cwa.googlegroups.com:
Ah, yes. There are three kinds of people in the world: those who can do
math, and those who can't. I fit into the third group. :-)


Actually there are 10 kinds of people. Those who understand binary and
those who don't. ;)

-mdb


11. There are also the kind that think they understand binary, but doesn't
=)

- Michael S
Dec 20 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: christopher diggins | last post by:
Here is some code I wrote for Matrix multiplication for arbitrary dimensionality known at compile-time. I am curious how practical it is. For instance, is it common to know the dimensionality of...
8
by: brian.digipimp | last post by:
I turned this in for my programming fundamentals class for our second exam. I am a c++ newb, this is my first class I've taken. I got a good grade on this project I'm just wondering if there is a...
12
by: Michael Culley | last post by:
I found this code in a project: StringBuilder sb = new StringBuilder(); sb.Append("SELECT * FROM SomeTable") .Append("WHERE SomeField = SomeValue") .Append("ORDER BY etc etc etc") at first I...
10
by: storyGerald | last post by:
Recently, I'm interested in writing very efficient code. Problem: there is a sequence { a(0), a(1), ..., a(n-1) } and a very small positive integer k, write an algorithm without using multiply...
60
by: Dave | last post by:
I'm never quite sure whether to use "this." or not when referring to fields or properties in the same class. It obviously works just fine without it but sometimes I wonder if using this....
83
by: deppy_3 | last post by:
Hi.I am started learning Programm language C before some time.I am trying to make a programm about a very simple "sell shop".This programm hasn't got any compile problem but when i run it i face...
20
by: laredotornado | last post by:
Hi, I'm using PHP 4.3. I have 15 pages in which I need to take the content of the BODY and put it in a little table ... <table> <tr><td colspan="3"><img src="header.gif"></td></tr> <tr>...
12
by: susiedba | last post by:
hey I want to execute VB 2005 code within a job in SQL 2000; all I see there is 'ActiveX script' is SQL 2000 going to support VB 2005 sometime soon? if not, is there an IDE that supports...
3
by: Ken Fine | last post by:
This is a question that someone familiar with ASP.NET and ADO.NET DataSets and DataTables should be able to answer fairly easily. The basic question is how I can efficiently match data from one...
25
by: Abubakar | last post by:
Hi, recently some C programmer told me that using fwrite/fopen functions are not efficient because the output that they do to the file is actually buffered and gets late in writing. Is that...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.