Pretty printing of DateTime values in C# - c#

I'm hoping that someone has found a way of doing this already or that there is a library already in existence. It's one of those things that would be nice but is in no way necessary for the time being.
The functionality I'm looking for is something like datejs in reverse.
Thanks,
Simon.
Thanks, using something like the dddd example might be a good start towards usability. The more I think about this problem the more it depends on the values being used. I'm specifically dealing with a series of timestamped versions of a document so there is a good chance that they will be clustered. Today isn't so hot if you have saved it three times in the last five minutes.
If I come up with something I'll share it with the community.

Actually, what you really want is the Custom DateTime Format strings:
http://msdn.microsoft.com/en-us/library/8kb3ddd4(VS.71).aspx
DateTime.Now.ToString("ggyyyy$dd-MMM (dddd)")
will return "A.D.2008$06-Nov (Thursday)" if that's what you want.
And to get something closr to datejs ("in forward"), you can use the same strings in DateTime.ParseExact()

http://msdn.microsoft.com/en-us/library/az4se3k1(VS.71).aspx should get you on your way,

Related

Accessing grid column values in VS2017

I am writing a chunk of code that takes a grid and does some processing. In this processing, I need to look at a field in the grid that is a DateTime type.
I've seen two different techniques for accessing the field and I was wondering if there was any consensus on which might be better. To be frank, I don't understand the syntax for the second one at all and haven't been able to find much of anything on it, but it's coming from someone who seems to know their onions and I wanted to see if it was much, much better, or if it was basically a draw.
So, what do you all think?
This one
d = (DateTime) row.Cells["DT0"].Value;
or this one?
d = row.Cells["DT0"].GetVal<DateTime>();
Or is there yet another, better, way?
Okay, so it looks like the second one was an in-house thing after all. Not sure why they did it as I have to move on and haven't had a chance to investigate it.
So it looks like the first one will do, providing I first check for
"if ( row.Cells[ "DT0" ].Value != null )"
Thank you all for your help!

Data structure for searching strings

I am looking for the best data structure for the following case:
In my case I will have thousands of strings, however for this example I am gonna use two for obvious reasons. So let's say I have the strings "Water" and "Walter", what I need is when the letter "W" is entered both strings to be found, and when "Wat" is entered "Water" to be the only result. I did a research however I am still not quite sure which is the correct data structure for this case and I don't want to implement it if I am not sure as this will waste time. So basically what I am thinking right now is either "Trie" or "Suffix Tree". It seems that the "Trie" will do the trick but as I said I need to be sure. Additionally the implementation should not be a problem so I just need to know the correct structure. Also feel free to let me know if there is a better choice. As you can guess normal structures such as Dictionary/MultiDictionary would not work as that will be a memory killer. I am also planning to implement cache to limit the memory consumption. I am sorry there is no code but I hope I will get a answer. Thank you in advance.
You should user Trie. Tries are the foundation for one of the fastest known sorting algorithms (burstsort), it is also used for spell checking, and is used in applications that use text completion. You can see details here.
Practically, if you want to do auto suggest, then storing upto 3-4 chars should suffice.
I mean suggest as and when user types "a" or "ab" or "abc" and the moment he types "abcd" or more characters, you can use map.keys starting with "abcd" using c# language support lamda expressions.
Hence, I suggest, create a map like:
Map<char, <Map<char, Map<char, Set<string>>>>> map;
So, if user enters "a", you look for map[a] and finds all children.

Is there an alternative to using List<string[]>?

I'm using:
List<string[]>
which works, but just feels so wrong! Does anyone have any correct more up date ways to achieve this or is it not wrong? I have tried the following, which works but also feels wrong:
List<List<string>>
For any moaners out there, my definition of wrong is hacky, out of date, old code, over complicated code, etc
Thanks
Edit:
Sorry guys, I forgot to mention the list length is un-known so it's likely to be large list with a non specified number of items, each array will consist of around 10-20 items
There isn't anything wrong with either of them, in the general case. There are certainly specific cases where one or the other may not be appropriate, but without any details there is no way of knowing whether this is an appropriate usage.
It's certainly not a pattern that you would globally consider bad. There's simply no reason for that to be the case.
I would put
List<string>
inside a class then use
List<Class>
the list length is un-known
If you don't know the length why not use List<List<string>>?
As mentioned before it's neither wrong nor hacky or overcomplicated. It's exactly what you need. A list of unknown length that contains lists of strings.

Customer Name Formatter

I have a feature request to implement automatic capitalisation of the name fields.
rachel mcMillan -> Rachel Mc'Millan
dara obriain -> Dara O'Briain
bill gates -> Bill Gates
etc...
seemed like an innocent request before, no?
Unfortunately with such generic search terms, I'm struggling to find any help. If I have to implement this myself then I'd need a list of "double" last names (Mc' Mac' O' ... etc ...) or something to work from, but it occurs to me that this must of been done before.
So I was wondering if someone could point me in the right direction?
Thanks,
D.R
I think the best way to approach this is to write a first approximation of a solution, i.e. turn everything into lowercase, capitalise first letters and handle extra cases you might think of.
Try going for an extensible solution and then just wait for requirement changes. It's the customer's job to provide you with the exact requirements. It will be their issue to differentiate the "O'Brian" and "Oblivious" cases.

Adding words to SQL Server Full Text Stemmer

I've dug around for a few hours now and cannot find an option to do this. What I would like to do is to add words to the stemmer used by Full Text in SQL Server. I work for an agency that would like to search on variations of names. In other words, if an officer enters the name of "Bill" I would also get a hit on "Will" or "William". Anyone know if this is possible?
I did look at implementing a custom IStemmable interface but that seems a bit of an overblow solution to this problem. Does anyone know of an easier way or have an off the shelf solution that will do this?
Thanks...
In SQL Server 2K5 or 2K8 it is called the "Thesaurus". Well doced in MSDN etc
It handles things like these
<expansion>
<sub>Internet Explorer</sub>
<sub>IE</sub>
<sub>IE5</sub>
</expansion>
<replacement>
<pat>NT5</pat>
<pat>W2K</pat>
<sub>Windows 2000</sub>
</replacement>
<expansion>
<sub>run</sub>
<sub>jog</sub>
</expansion>
Sigh....
Thanks. One of those times I was definitely trying to make it more difficult then it needed to be. I think I found stemmer early on and kept using it in my searches.
Thanks again.

Categories