|
J4amieC wrote: Consider using a StringBuilder rather than lots of string concatenation using +=
If the strings are known at compile time, the compiler will generate one big string for you. Try compiling this and taking apart the EXE with ildasm and you will see what I mean.
using System;
class Foo
{
public static int Main(string[] args)
{
string s = "Hello, " + "world!";
Console.WriteLine(s);
return 0;
}
}
Cheers,
Vıkram.
Stand up to be seen. Speak up to be heard. Shut up to be appreciated.
|
|
|
|
|
As J4amieC says, you can use the Stringbuilder. But you can also use String.Format();
Very easy to use:
String javaScript = String.Format(@"
<javascript> etc. </javascript>
<and other="" stuff="" here=""></and>
{0} <- a variable
{1} <- another variable", variable1, variable2);
|
|
|
|
|
String.Format() uses StringBuilder internally.
|
|
|
|
|
I do a lot of dynamically created JavaScript in my ASP.Net development. I use a pattern similar to this:
protected void Page_PreRender(object sender, EventArgs e)
{
RegisterClientScript();
}
protected void RegisterClientScript()
{
if (!(Page.ClientScript.IsStartupScriptRegistered("myJS"))
{
StringBuilder js = new StringBuilder();
js.AppendLine("TargetDate = 'friday';");
js.AppendLine("BackColor = 'palegreen';");
js.AppendLine("ForeColor = 'navy';");
js.AppendLine("CountActive = true;");
js.AppendLine("CountStepper = -1;");
js.AppendLine("LeadingZero = true;");
js.AppendLine("DisplayFormat = '%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.';");
js.AppendLine("FinishMessage = 'It is finally FRIDAY!'");
Page.ClientScript.RegisterStartupScript(this.GetType(), "myJS", js.ToString(), true);
}
}
"We are men of action; lies do not become us."
|
|
|
|
|
Thank you everyone for the replies. I apologize, I'm not as familiar with Javascript yet, which is why up until now I would do more logic and coding in the C# behind pages and then just call the strings as needed. I've setup my page behind using the code above and it appears to insert the code properly, however it's still not working correctly. What I am trying to do is have the "TargetDate dynamically change to that week's upcoming friday. If I goto my asp page and put this in, it works just fine:
<script language="JavaScript">
TargetDate = '12/12/2008 12:00:00 AM';
BackColor = 'palegreen';
ForeColor = 'navy';
CountActive = true;
CountStepper = -1;
LeadingZero = true;
DisplayFormat = '%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.';
FinishMessage = 'It is finally FRIDAY!';
</script>
<script language="JavaScript" src="countdown.js"></script>
I then rip out the first script part and use the outlined code above. This will start the countdown timer but it can't find any of the settings I have in place. If I do a view source of the page, at the very bottom of the page I now see this:
<script language="JavaScript">
TargetDate = '12/12/2008 12:00:00 AM';
BackColor = 'palegreen';
ForeColor = 'navy';
CountActive = true;
CountStepper = -1;
LeadingZero = true;
DisplayFormat = '%%D%% Days, %%H%% Hours, %%M%% Minutes, %%S%% Seconds.';
FinishMessage = 'It is finally FRIDAY!';
</script>
I'm starting to wonder now if it makes more sense to just modify the "countdown.js" and put the switch statements in there to always update the date.
Again, thank you for all of your help!
"You're damned if you do, and you're damned if you dont" - Bart Simpson
|
|
|
|
|
Is there any solution to run PowerShell 1.0 in C# remotely? Can't run PowerShell 2.0 in Windows XP, right?
Thank you!
|
|
|
|
|
Hi all
I am trying to take an XML response from a web server and putting it into a Dataset
I am using a streamreader to pass the xml stream to the readxml method of the dataset, however I am finding that I am not getting all the data..
this might explain myself better.. if i do this:
HttpWebResponse oResp = (HttpWebResponse)myReq.GetResponse();
StreamReader oResultSR = new StreamReader(oResp.GetResponseStream(), encoding);
sMessage = oResultSR.ReadToEnd();
TextWriter tw = new StreamWriter(@"c:\hmmm.txt");
tw.WriteLine(sMessage);
tw.Close();
that works fine and my text file has all the xml data I need
however if i do this (which i want):
HttpWebResponse oResp = (HttpWebResponse)myReq.GetResponse();
StreamReader oResultSR = new StreamReader(oResp.GetResponseStream(), encoding);
DatasetXML[a].ReadXml(oResultSR);
DatasetXML[a].WriteXml(@"c:\hmmm.xml");
it only gives me the 1st node of the xml and not the rest
anyone know why?
|
|
|
|
|
can anyone help me with this please?
|
|
|
|
|
Hi All,
i'm trying to write a program where the button1_Click event will start a new thread and everything within the button1_Click runs within this thread, rather than starting new threads within the button1_Click.
so, i want this:
thrd_1 = new Thread(new ThreadStart(button1_Click));
private void button1_Click(object sender, eventArgs e)
{
things to do 1
things to do 2
}
rather than
private void button1_Click(object sender, eventArgs e)
{
thrd_1.start()
thrd_2.start()
}
i hope this makes sense!
Many thanks,
Phil
|
|
|
|
|
so what exactly is your question? from what it looks like you already have the answer.
Prateek
|
|
|
|
|
Hi, thanks for replying so quickly.
the problem is it won't compile. it errors saying - No overload for button1_Click matches delegate 'System.Threading.ThreadStart.
|
|
|
|
|
You must do it like in the second solution, the first one won't work.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
The error message explains it...
The ThreadStart delegate looks like this:
public delegate void ThreadStart()
Are you looking for something like this?
private void button1_Click(object sender, eventArgs e)
{
thrd_1 = new Thread(new ThreadStart(button1_Clickthread));
thrd_1.start()
}
private void button1_Clickthread()
{
things to do 1
things to do 2
}
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
how to create simple animations using the Visual studio 2008
|
|
|
|
|
WPF provides built in support for animation.
|
|
|
|
|
do you have some flash files that you are going to use?
Cheers!!
Brij
|
|
|
|
|
Using visual studio? You mean you want to animate the IDE or do you want to write a program, using vS 2008, that does animation?
If the former - I have no idea.
If the latter - more info please! I'm guessing C# (as this would be the right forum) but what do you want to do? Bounce a ball around the form? MOve a label up and down? Show an AVI?
If I knew then what I know today, then I'd know the same now as I did then - then what would be the point?
.\\axxx
(That's an 'M')
|
|
|
|
|
I have a requirement to display all the application programs started by a user during a specific time period.
I don't want to list all the processes currently running.
Only the programs explicitly invoked by a user such as opening a notepad, control panel, my computer properties, internet explorer, ms word etc.
Is this achievable?
thanks in advance
Fadi
|
|
|
|
|
How does your problem relate to C#?
xacc.ide - now with TabsToSpaces support IronScheme - 1.0 beta 1 - out now! ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))
|
|
|
|
|
The requirement is part of the c# application which i am currently working on.
If you feel it should have been some posted in some other section, pls suggest it.
|
|
|
|
|
Member 3467902 wrote: working on.
so what have you done so far?
Harvey Saayman - South Africa
Junior Developer
.Net, C#, SQL
you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer)
1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111
|
|
|
|
|
|
Thanks alot..... I will try like that......
|
|
|
|
|
You are welcome
|
|
|
|
|
Hello aLL,
I am trying to create windows form on the fly by looking at the value coming in form of a string.
for example:- i have form by name frmMain i will be getting this name from a string during runtime.
I am not getting how to create an instance of an object of type frmMain
Thanks in Advance
Regards
Bharath
Ron
|
|
|
|