|
leppie wrote:
and paste less code
Oops, was asuming more was better.
I just want to know if my string exists in the array. In the debugger I can see that it does exist.
For example. I have a column named Amount billed. The strings in my array are {"Amount","Cost"}. I am using IndexOf to search the ColumnName for one of the strings in the array.
It doesn't find "Amount" for some reason.
Thanks
Robert
|
|
|
|
|
It should work. maybe it something else your doing
int iCOunt = -1;
foreach ( string s in strCurrency )
{
iCount++;
if ( s.IndexOf(ColumnName) != -1 )
return iCount;
}
|
|
|
|
|
No, I had it backwards. I was looking to see if s existed in ColumnName. so I needed to put ColumnName.IndexOf(s) instead of s.IndexOf(ColumnName).
Such is life.
Robert
|
|
|
|
|
I think what you're asking is to see if a particular string is in an array of strings. Use this:
public bool ExistsInArray(string s, string[] sList)
{
foreach (string item in sList)
{
if (item == s) return true;
}
return false;
}
In other words, check all strings in the list to see if the one I want is there. If it is, exit immediately I find it, returning true. If I fall through the loop, having checked all strings in the list, return false.
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
but if you do "==" arent you just comparing the instances and not the value
s.Equals(ColumnName)
|
|
|
|
|
No. The == operator for strings is overridden to compare the actual string contents.
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
well cool
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
I need to count the number of new lines(\n) in a string.
I thought about using regular expressions, but I do not really understand them very well. .NET also does not provide a way to get this information. The only other way I can think of doing it is writing a function to count them through other string functions, if there is a faster or better way to do it I would really like to know.
|
|
|
|
|
Check out the StringReader class. You could do something like:
public static int CountLinesInString(string str)
{
System.IO.StringReader strR = new System.IO.StringReader(str);
string temp = strR.ReadLine();
int count = 0;
while(temp != null)
{
count++;
temp = strR.ReadLine();
}
return count;
}
This would count the lines in the string. But this might not be exactly what you are looking for if you want an exact count of the character '\n'.
Hope this helps,
Nathan
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
Actually the StringReader class will work better for what I want to do. Thanks for pointing me to it.
|
|
|
|
|
No problem... I am glad I could help.
---------------------------
Hmmm... what's a signature?
|
|
|
|
|
|
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.
|
|
|
|