|
How do i create a program using c# to block unwanted access to certain website such as playboy.com?
|
|
|
|
|
If you are creating your own browser, then you could parse the urls/links for for words or sites in a dictionary. When a match occurs you could immediately redirect to another webpage.
Regards,
Thomas Stockwell
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.
Visit my homepage Oracle Studios[ ^]
|
|
|
|
|
using system.ole
Hussaingreat
|
|
|
|
|
Listen ..
We're more than keen on helping you out, but this is absolutely too little information.
Or maybe I should just anwser just as thoughfully as you asked your question.
try this :
for (int i=1;i < 500; i++)<br />
{<br />
Console.WriteLine(i.ToString() + " : I need to give more information");<br />
}
|
|
|
|
|
Is there any build-in method to compare byte array or do I have to do it manualy ?
|
|
|
|
|
I don't believe there's a built in function, and I've seen some pretty *interesting* ways people have done it, but bytewise comparison is simple and fast unless you're talking GBs of data.
static bool compareByteArrays(byte[] arr1, byte[] arr2) {
int len, i;
for(i = 0, len = arr1.Length; i < len && arr1[i] == arr2[i]; i++);
return i == len;
}
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
Hey
try this :
public static bool ArraysEqual(byte[] by1, byte[] by2)<br />
{<br />
if ( by1 == null )<br />
throw new ArgumentNullException("by1");<br />
if ( by2 == null )<br />
throw new ArgumentNullException("by2");<br />
<br />
if ( by1.Length != by2.Length )<br />
return false;<br />
<br />
for(int i=0; i < by1.Length; i++)<br />
{<br />
if ( by1[i] != by2[i] )<br />
return false;<br />
}<br />
return true;<br />
}<br />
Hope this helps
Cheers
|
|
|
|
|
Thank you both
I will so write my own one because I need an equivalent to memcmp, not returning a bool but an integer telling who is greater
|
|
|
|
|
Hello
I need to use a BinaryReader to read strings but I want to know how to prepare string in my file
This is to documentation comment :
Reads a string from the current stream. The string is prefixed with the length, encoded as an integer seven bits at a time
Does it mean that a string can't be longer than 127 bytes (7 bits integer) ??
|
|
|
|
|
I use the following method to read files. Its pretty fast and then you could use regular expressions to find text within the returned string or what ever else you need to do with the content.
<br />
public string DecodeFile(string fullpath)<br />
{<br />
if (File.Exists(fullpath) == false)<br />
throw new FileNotFoundException();<br />
<br />
try<br />
{<br />
FileStream fStream = File.OpenRead(fullpath);<br />
byte[] buffer = new byte[fStream.Length];<br />
int bytesRead;<br />
bytesRead = fStream.Read(buffer, 0, buffer.Length);<br />
fStream.Close();<br />
fStream.Dispose();<br />
<br />
if (bytesRead <= 0)<br />
throw new Exception("Empty file.");<br />
<br />
Decoder decoder = Encoding.Default.GetDecoder();<br />
char[] cBuffer = new char[buffer.Length];<br />
<br />
int bytesConverted, charsConverted;<br />
bool bCompleted;<br />
<br />
decoder.Convert(buffer, 0, buffer.Length, cBuffer, 0, buffer.Length, false, out bytesConverted, out charsConverted, out bCompleted);<br />
return new String(cBuffer, 0, bytesConverted);<br />
}<br />
catch (Exception ex)<br />
{<br />
throw new Exception(ex.Message);<br />
}<br />
<br />
}<br />
Google search lead me to this info
"Well, its not quite that simple. int.MaxValue is the most the string class
itself could handle, you are right, but since characters take up two bytes,
that many characters would go way beyond the max possible allocation. The
best theoretical high value is 2^31(or 2147483648) characters, since that is
exactly how many would fit in memory. Practially it'd be much, much smaller."
http://bytes.com/forum/thread481655.html[^]
Just because we can; does not mean we should.
|
|
|
|
|
Hello
This can be good for little file but if you have to manage a few very big files it does not seems to be a good approach
And it does not give me the answer to my question : what is 7 bits encoded integer. Does it limit string lenght to 127 bytes ?
|
|
|
|
|
Take a look at the BinaryReader.Read7BitEncodedInt, BinaryWriter.Write7BitEncodedInt.
The 7 bits integer means that a 32 or 64 bit int can be written in a single byte if the value of the int does not exceeds 7bit (127 decimal). This is done to save space, i.e. an int instead of 4 or 8 bytes may be saved in a single byte.
|
|
|
|
|
Thank you
Finaly thank to you I've found on internet how to build an 7 bit encoded integer !
|
|
|
|
|
I work with a guy that is always talking about how many flops[^] a particular activity takes. Quoting him directly HOWEVER, when passing the information from method to method, an arraylist is not the most efficient taking up to 60,000 flops to pass the information therefore arrays are faster. I asked him once where he got this information and was told that somebody at Microsoft told him. Does anybody know where there is any written documentation about this? I would like to learn more about this to become a more efficient coder. References to information would be very helpful. I have Googled for this info and not found it, so any help is appreciated.
Hogan
|
|
|
|
|
With the risk of going completely out of line here ( forgive me if I do ) , but I think the term 'flop' is something that this particular engineer dreamed up himself. I've never encountered nor heard of 'flops' when parsing information.
What's more .. the engineer contradicts himself by say that arraylist is not the most efficient and a bit further up therefore arrays are faster Faster to what ?
Cheers
|
|
|
|
|
I believe he is referring to the term I linked to in my first article.
Hogan
|
|
|
|
|
Flops refers to the number of FLoating point Operations Per Second.
|
|
|
|
|
Have you tested it by collecting the DateTime before the method and the DateTime afterwards and then calculating the difference to see what is actually faster? I know your looking for documentation, but never throw out good old fashioned testing.
Just because we can; does not mean we should.
|
|
|
|
|
Yeah, I've done tests... Proved the exact opposite. But he wouldn't even look at my test program to see the results. I was hoping for more data... Not that it would be read.
Hogan
|
|
|
|
|
Wow. He's trying to hide his complete ignorance by dropping buzzwords on people. Measuring the speed of an activity in FLOPS is like measuring the speed of a car in liters of Gas per hour.
|
|
|
|
|
That is a proven tactic when you're absolutely clueless about what you are doing.
A skill commonly found in managers s
|
|
|
|
|
Dave Kreskowiak wrote: Measuring the speed of an activity in FLOPS is like measuring the speed of a car in liters of Gas per hour.
Now you cause me to doubt my comprehension of this. FLOPS would be specific and consistent on the particular system yes? So doesn't work for the OPs statement since ArrayList processing is going to run at the same per second rate as anything else on that system, yes? However a car operates at a variable rate of speed so, my head esplode like a liter of Gas!
led mike
|
|
|
|
|
ignorance == incompetence?
|
|
|
|
|
I'm also having problems comprehending how much floating point arithmetic .Net needs to copy memory.
I'm largely language agnostic
After a while they all bug me
|
|
|
|
|
I'm also having problems comprehending how much floating point arithmetic .Net needs to perform to copy an 8 byte pointer
I'm largely language agnostic
After a while they all bug me
|
|
|
|