|
Aha, I see you remembered that one!
greetings
|
|
|
|
|
Hello Luc,
Luc Pattyn wrote: Aha, I see you remembered that one!
Hmmm, not really!
Have I stolen it from you?
If yes, I will change my message, to bring credit to you.
All the best,
Martin
|
|
|
|
|
Hi Martin,
that was my reply months ago to a similar question, look here[^] for
a more compact form of it.
So either you read it and remembered the base idea unknowingly,
or you just reinvented it, it does not really matter.
Nothing got stolen, no problem; chances are I saw
it elsewhere a long time ago, I don't recall.
|
|
|
|
|
All the best,
Martin
|
|
|
|
|
Or
int i = new List<char>("mississippi".ToCharArray()).FindAll(delegate(char c) { return c == 'i'; }).Count;
Not very maintainable, expensive, possibly slow, but fun!;)
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
|
|
|
|
|
thanks malcom..but im still confused![Confused | :confused:](https://www.codeproject.com/script/Forums/Images/smiley_confused.gif)
|
|
|
|
|
What are you confused about? I suppose we (I) went over the top throwing working but not helpful solutions at you. Detail, clearly, exactly what you want, why these solutions don't work, and we will help. Or at least try.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
|
|
|
|
|
You started programming in APL I trust ?
|
|
|
|
|
No, BBC Basic --> Clipper Summer '87 --> C --> C++ --> C#
Just obsessed with delegates (CG's fault partly) and what can be done with them!
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
|
|
|
|
|
I like delegates too, but not that much; I typically try to keep a balance between
the easiest solution to come up with and the best maintainability (these are
not always identical). APL was the language that triggered lots of contests
a la "see what I can do in one line..."
But anything you can do without delegates, you can do with one or more delegates too.
Why not have your Main launch your main form with some delegate ?
|
|
|
|
|
Did a double take then realized how it worked. That is a truely hideous hack .. I love it
Why write in 20 lines what you can in-line in 1
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
Or (I like most):
string TextToParse= "mississippi";
string TextToSearch= "i";
int Found = 0;
for(int startpoint=TextToParse.IndexOf(TextToSearch,0);startpoint>-1;startpoint = TextToParse.IndexOf(TextToSearch,startpoint+1))
{
Found++;
}
All the best,
Martin
|
|
|
|
|
1st :string str ="mississippi"; (for example),otherwise str store the string after taking the input by user
2nd :char ch ="i"; (for example),otherwise ch store the chracter after taking the input by user
3rd : int c=0;
4th :for(int i=0;i
|
|
|
|
|
only works with single characters...OP wanted words as well I think
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
|
|
|
|
|
OR (beat this...;P)
string test = "this is the test to see if this returns three to this string";
string stringToFind = "this";
Console.Write(new Regex(stringToFind, RegexOptions.Multiline).Count);
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
|
|
|
|
|
I think, nobody (without the intention todo so) will beat this performance leak! ;)
All the best,
Martin
|
|
|
|
|
Why? Are Regular Expressions slow and shouldn't be used? I've never used them in production...tell me more.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
|
|
|
|
|
Apart from that, it doesn't even compile!
All the best,
Martin
|
|
|
|
|
using System.Text.RegularExpressions; ??
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
namespace RegExTest
{
class Program
{
static void Main(string[] args)
{
string test = "this is the test to see if this returns three to this string";
Console.WriteLine(new Regex(stringToFind, RegexOptions.Multiline).Count);
}
}
}
Does for me.
-- modified at 5:55 Friday 3rd August, 2007
See later post - finger trouble!!
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
|
|
|
|
|
Ahh,
You are using .Net >1.1 (I only have 1.1)
In my case the Regex class does not provide a "Count" property.
Also "using System.Collections.Generic;" is not possible for me.
But apart from that, where is your connection from the "test" string to the Regex?
All the best,
Martin
|
|
|
|
|
Sorry - my internet box is not my dev box and I can't copy type
I meant
Console.WriteLine( new Regex(stringToFind, RegexOptions.Multiline).Matches(test).Count);
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
|
|
|
|
|
Ok,
I did a test with a loop over 10000 to show the difference.
one with:
for(int loop = 0;loop<10000; loop++)
{
Found=0;
for(int startpoint=TextToParse.IndexOf(TextToSearch,0);startpoint>-1;startpoint = TextToParse.IndexOf(TextToSearch,startpoint+1))
{
Found++;
}
}
timespan: "00:00:00.0312498"
and the regex:
for(int loop = 0;loop<10000; loop++)
{
Found = new Regex(TextToSearch, RegexOptions.Multiline).Matches(TextToParse).Count;
}
timespan: "00:00:00.1249992"
Shows factor 4. (Off corse, it is not allways factor 4)
All the best,
Martin
|
|
|
|
|
Its even more noticable when you ramp the loop up to 1M.
But....parse a really long string - eg 8k. The figures then swap round. reg ex is a lot quicker.
"More functions should disregard input values and just return 12. It would make life easier." - comment posted on WTF
|
|
|
|
|
Yes, using Regex has to be validated new for every task!
All the best,
Martin
|
|
|
|
|
Hi,
I want to manipulate the data as a small part of my project.In short I have an array[250,200] ,where numbers(actullay binary no.s) are stored .For simply let`s
int[,] array;<br />
array = new int[5, 5]; data are stored in array[,] as :
12345
12345
12345
12345
12345 OR
123451234512345123451234512345
I want manipulate the data as:
12345
54321
12345
54321
12345 OR
1234554321123455432112345
Means that :
Array[0,0]= Array[0,0];<br />
Array[0,1]= Array[0,1];<br />
Array[0,2]= Array[0,2];<br />
Array[0,3]= Array[0,3];<br />
Array[0,4]= Array[0,4];<br />
<br />
Array[1,0]= Array[1,4];<br />
Array[1,1]= Array[1,3];<br />
Array[1,2]= Array[1,2];<br />
Array[1,3]= Array[1,1];<br />
Array[1,4]= Array[1,0];<br />
<br />
<br />
Array[2,0]= Array[2,0];<br />
Array[2,1]= Array[2,1];<br />
Array[2,2]= Array[2,2];<br />
Array[2,3]= Array[2,3];<br />
Array[2,4]= Array[2,4];<br />
<br />
Array[3,0]= Array[3,4];<br />
Array[3,1]= Array[3,3];<br />
Array[3,2]= Array[3,2];<br />
Array[3,3]= Array[3,1];<br />
Array[3,4]= Array[3,0];<br />
<br />
Array[4,0]= Array[4,0];<br />
Array[4,1]= Array[4,1];<br />
Array[4,2]= Array[4,2];<br />
Array[4,3]= Array[4,3];<br />
Array[4,4]= Array[4,4];
Please send the strong and efficient logics because I have array[250,200]
![Confused | :confused:](https://codeproject.global.ssl.fastly.net/script/Forums/Images/smiley_confused.gif)
|
|
|
|
|