|
Domains aren't case sensitive. abc.com is the same as ABc.Com. If you're comparing, just lower case it.
Use a regular expression for the domain part. Protocol doesn't matter. You're just interested in the domain name. From there, you can build a URL and validate it. Anything after a / is content, as per your example.
|
|
|
|
|
Thanks Bert!
Are there any existing regular expression to make a reference? I think it should be a common problem.
regards,
George
|
|
|
|
|
George_George wrote: Are there any existing utility class to do this? Not all URLs begins with protocol part, like http://, and not all ends with /, so I feel hard when I try to write a parser by myself;
Yes. System.Net.Uri class does this.
Uri uri = new Uri("http://abc.com/some/address/abc.html");
Console.WriteLine(uri.Host);
George_George wrote: Is domain case sensitive or not? i.e. abc.com the same as ABc.Com?
Usually domains are not case sensitive. But some web servers like APACHE, consider the folder names as case sensitive. Which means, www.abc.com will be equal to www.ABC.com , but www.abc.com/somefolder won't be equal to www.abc.com/SomeFolder according to apache.
|
|
|
|
|
Cool, N a v a n e e t h!
I like your solution.
regards,
George
|
|
|
|
|
Hello everyone,
Suppose I have a Dictionary object instance, Dictionary<string, int>, the int is always positive. I want to get top 10 elements from the Dictionary with the maximum 10 int values, any efficient way to do this?
thanks in advance,
George
|
|
|
|
|
George_George wrote: I want to get top 10 elements from the Dictionary with the maximum 10 int values,
it's not clear. Can you explain it ?
|
|
|
|
|
Sorry for my English, N a v a n e e t h!
Here is a sample, suppose I have a dictionary <string,>. Here is a sample content,
("entry1", 1);
("entry2", 2);
("entry3", 3);
("entry4", 10);
("entry5", 5);
then top 2 (from the value of key/value pair point of view) is entry 4 and entry 5. I want to retrieve top 10, any efficient solutions?
regards,
George
|
|
|
|
|
Oh, so by top, you actually mean bottom?
Perhaps something like:
int[] values = list.Values.ToArray();
values.Sort();
int tr = values[values.Length - 10];
List<KeyValuePair<string,int>> = list.Where(item=>item.Value>=tr).ToList();
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks Guffa,
I am sorting a Dictonary< , > but you are sorting a List<>? I am confused about your code? For your code list.Values.ToArray(), where does the list variable comes from?
regards,
George
|
|
|
|
|
Sorry about the confusing name. The list variable is the dictionary...
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks Guffa!
I read your code again, but confused about the following statement.
1.
From left side of the assignment, do you miss a variable name?
2.
What does this operator mean <ptr>item=>item.Value>=tr?
List<KeyValuePair<string,int>> = list.Where(item=>item.Value>=tr).ToList();
regards,
George
|
|
|
|
|
George_George wrote: From left side of the assignment, do you miss a variable name?
Correct.
George_George wrote: What does this operator mean item=>item.Value>=tr?
It's a lambda expression. When it's not turned into an expression object it's equivalent to a delegate, which you can use if you don't have C# 3:
delegate(KeyValuePair<string,int> item){ return item.Value >= tr; }
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks Guffa,
I read and studied again about your pseudo code, I think it has good idea. But my current confusion is, there is no members called "where" as you used in your sample.
I am using C# 2.0, and can not use other version, like C# 3.
It is appreciated if you could re-write your sample code to make your ideas more clear?
regards,
George
|
|
|
|
|
Ok, then you have to do it the old fashoned way:
int[] values = dictionary.Values.ToArray();
values.Sort();
int tr = values[values.Length - 10];
List<KeyValuePair<string,int>> result = new List<KeyValuePair<string,int>>();
foreach (KeyValuePair<string,int> item in dictionary) {
if (item.Value >= tr) {
result.Add(item);
}
}
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Thanks Guffa,
Smart!
regards,
George
|
|
|
|
|
Quickly, off the top of my head, you could create a linked list of objects with which you will do an insertion sort. You then run the dictionary, inserting objects into the array ONLY if the value is higher than the value at position zero OR if the array is empty. When inserting a new object, just insert it in the correct place.
Wow, I was being exceptionally thick tonight. I just realized that you could just use an OrderedDictionary.
Anyone who thinks he has a better idea of what's good for people than people do is a swine.
- P.J. O'Rourke
modified on Tuesday, July 22, 2008 2:56 AM
|
|
|
|
|
Thanks Joe,
This is what I am doing currently, I think this approach is manual and I want to find whether there are some existing classes/APIs could do this -- sort by value or key/value pair?
regards,
George
|
|
|
|
|
Hello All--
I have a List<double[]> Values, where each double[] is an array representing one series (not from a database). I can have several dozen double[] and each can be 100k+ items.
I would like to display this to the user in a datagrid (I know this is a lot of information, but the user needs to be able to browse). Due to the size, it is prohibative to load the entire thing into the grid at once, instead loading rows as needed. From Google, it seems like I need to bind this data source to the datagrid.
I've tried this:
currencyManager = (CurrencyManager)dataGridViewData.BindingContext[Data.Values];
dataGridViewData.DataSource = Data.Values;
But this displays the property of each List<> item (the double[]) in the grid (length, rank, etc).
Any suggestions on how to properly bind this data source?
Thanks
modified 12-Jul-20 21:01pm.
|
|
|
|
|
Hi all...
this is for an chat application....
i want to get system ideal time for setting the user status to ideal in the chat....
supposs if the system is ideal for 2 minut, I want to change the status of the logged in user to Ideal.
so can anyone help me to solve this problem....
Thanks in Advance
Vayanan
|
|
|
|
|
|
Hi Luc
Thank u very much
regards Vayanan
|
|
|
|
|
Hi,
Is there some macro recorder in c# like the VB macro recorder in MS Excel?
I have visual studio 2008 pro, i hoped it to be there when editing excel in visual c#.
Thanks
|
|
|
|
|
nelsonpaixao wrote: I have visual studio 2008 pro, i hoped it to be there when editing excel in visual c#.
I know there is one, not sure about the pro version, but I have that installed at work, so I can look for you in about 8 hours
|
|
|
|
|
Yes the Pro version does have a macro recorder.
|
|
|
|
|
I have a DataTable (dt) with a DataColumn (dc) whose Datatype is System.Int64.
I want this column to display the 64 bit Int in Hexadecimal format, as if the number had been converted like Int64Data.ToString("X") .
What property of a column controls this display? There's no "format" property for a column, and "Expression" appears to be for aggregation.
It's important that the column datatype remain INT64 (and not string), or I would just do the formatting conversion myself.
Can somebody point me to the correct method for setting the column display formatting?
Thanks.
|
|
|
|