|
I'd say keep it simple and direct:
public int CountNewLines(string s)
{
int result = 0;
foreach (char c in s)
{
if (c == '\n') result++;
}
return result;
}
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
C#:
<font color="blue">private</font> <font color="blue">void</font> button6_Click(<font color="blue">object</font> sender, System.EventArgs e) <br> { <br> <font color="#0000FF">int</font> x="some\nstuff\nwith\nnewlines\nin".Split('\n').getupperbound(0);<font color="DarkGreen"> <br></font> MessageBox.Show(x.ToString()); <br> }
that gives you the amount of \n in the string
|
|
|
|
|
Very nice
|
|
|
|
|
Ahh, akin to using the SUV to get the mail
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
Check this out...
private void buttonProgress_Click(object sender, System.EventArgs e)
{
string byteFile2=this.textBoxActiveData.Text;
<big>this.timer2.Tick += new System.EventHandler</big>(this.timer2_Tick);
FileInfo myFileInfo = new FileInfo(byteFile2);
long lSize = myFileInfo.Length;
string gNiggas=lSize.ToString();
seconds=lSize/350;
}
on the Event Handler line, what is the += doing?
here is what it is calling...
protected void timer2_Tick (object sender, System.EventArgs e)
{
this.timer2.Start();
int f=1;
int p=1;
for(f=1; f<20; f++)
{
p++;
if(f==19)
{
f=200;
this.timer2.Stop();
MessageBox.Show(f.ToString());
}
progressBar.Value=p;
}
progressBar.Value=0;
}
anyways... the problem is...
I can run the timer2_Tick once. But when I click on the button again it won't go... what is stopping it from re executing?
/\ |_ E X E GG
|
|
|
|
|
eggie5 wrote:
what is stopping it from re executing?
This line: this.timer2.Stop();
You need to start the timer again in buttonProgress_Click . Also move
this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
line to the constructor or any place where it will run only once.
Alexandre Kojevnikov
MCAD charter member
Leuven, Belgium
|
|
|
|
|
I don't understand what you want me to do with ....
this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
/\ |_ E X E GG
|
|
|
|
|
you need to put :
this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
in an area like the "#region Windows Form Designer generated code" is what Alexandre was trying to say. then the timer will always work when you click the button
|
|
|
|
|
oops lost my name for that post ^^^^^
|
|
|
|
|
eggie5 wrote:
I don't understand what you want me to do with ....
this.timer2.Tick += new System.EventHandler(this.timer2_Tick);
Move it to the constructor, just after InitializeComponent();
Alexandre Kojevnikov
MCAD charter member
Leuven, Belgium
|
|
|
|
|
I would suggest the delegate part 2 article on this site
|
|
|
|
|
eggie5 wrote:
on the Event Handler line, what is the += doing?
The idea between events and delegates here is that when your timers tick event is fired you want to register a new method to be called, hence a callback function which is defined under .NET as a delegate. Essentially there is a linked list of functions that allow you to either += add or -= remove delegates from the chain. You should probably just specify the event/delegate within your constructor code, there is no reason to re-register this everytime.
-Nick Parker
|
|
|
|
|
Hi,
I want to know something about remote installation of a .NET project(C#). I want my setup files(.exe,.msi etc) to reside on the webserver and when a certain user goes to a certain url that points to the location of the installation files, the online installation starts. If ever u would have come across the online installation of yahoo messenger, well that is what i want to achieve. How can that be done. Does .NET provide any means to do this or there is some java script for this? Please tell me step wise.
|
|
|
|
|
I think Y! does that with the help of activex controls, you can write one in VC++ if you want to achieve the same.
For c# you can take a look at the updater application block, I haven't gone through it, but I believe this was created to auto-update applications from a web server
http://msdn.microsoft.com/library/en-us/dnbda/html/updater.asp[^]
p.s you are hurting my eyes with your post, there is no need to put all of the stuff in all bold
Cheers,
Kannan
|
|
|
|
|
Hi,
Recently, the User Interface Process Application Block made by Edward Jezierski (Microsoft Corporation), Michael Stuart (Microsoft Corporation), Lin Joyner (Content Master Ltd), and Pablo Cibraro (Lagash Systems) was released by Microsoft as part of their Application Blocks for .NET.
Since I'm a currently implementing a MCV pattern in our current application I badly needed to study UIP Application Block. But the UIP Solution is in VS.NET 2003 format, so I migrated all the code and created a Solution that can run on VS.NET 2002. So far I have a working copy of the UIP Application Block Source Code (with one migrated example) that runs pretty well in VS.NET 2002. I have studied the code and since we are using windows form, rather than ASP, I have no choice but to create a struts-like controller to suit are project's core engine.
In order not to put my effort to waste, I'm sharing the migrated solution to anyone interested to study/implement further the UIP using VS.NET 2002.
Just reply to this post if you need the code.
for more details on UIP (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/uip.asp)
|
|
|
|
|
Hi,
How can I do similarity detection in .NET? The main question is how to calssify two related news.
Any idea?
Nothing
|
|
|
|
|
|
leppie wrote:
42?
Maybe the infinite improbablity drive would work in this situation?
iid[^]
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
What is a quick way to get the size of a file?
/\ |_ E X E GG
|
|
|
|
|
Really quick example (the FileInfo class provides a Length property to identify the size of the current file):
string dirName = "C:\\";
DirectoryInfo dirInfo = new DirectoryInfo(dirName);
Console.WriteLine("{0} contains the following files:", dirName);
Console.WriteLine("Size\t Filename");
foreach (FileInfo fileInfo in dirInfo.GetFiles())
{
try {
Console.WriteLine("{0}\t {1}",
fileInfo.Length, fileInfo.Name);
}
catch (IOException e) {
Console.WriteLine("\t {0}: {1}", fileInfo.Name, e.Message);
}
}
-Nick Parker
|
|
|
|
|
thanks for the quick response.
that's just what I needed.
/\ |_ E X E GG
|
|
|
|
|
Hi! I have a interesting question : but i don't know !
Main()
{
Form fm = new Form();
fm.Show(); --> (1) ( or fm.ShowDialog() --> (2) )
Application.Run();
Application.Run(new Form()); --> (3)
}
What is difference between (1) , (2) and (3)? thx!
|
|
|
|
|
No. 3 create a new thread of your application but number 1 and 2 create child forms,so not new thread of appplication.
For number 1 and 2 from MSDN:
ShowDialog:
Shows the form as a modal dialog box.Show:
Show:
Showing the control is equivalent to setting the Visible property to true. After the Show method is called, the Visible property returns a value of true until the Hide method is called.
Mazy
No sig. available now.
|
|
|
|
|
1 shows it modeless, 2 shows it as a dialog box (modal) and 3 doesn't show it all.
What would really be amazing is if you wrote that code asnd using a debugger you tested it out yourself.
|
|
|
|
|
currently have a tree menu that allowes nodes to be added and selected, however i am trying to make it so that the parent/root node can't be selected.
to achieve this i have been through if statements but if anybody could post some code it would be most helpful!
thanks in advance
|
|
|
|