When coding is harder than it should be...
-
You know when you sometimes know you want to do something, and you have the whole process visualized elegantly in your mind, and when you get to writing the code, you realise you totally underestimated the complexity of the problem. :wtf: Today I just hit such a problem.[^] [edit] Found my answer @ http://www.codeproject.com/useritems/ahocorasick.asp[^] ;) [edit] xacc.ide-0.1.1.2 released! :) Download and screenshots -- modified at 17:31 Friday 30th December, 2005
-
You know when you sometimes know you want to do something, and you have the whole process visualized elegantly in your mind, and when you get to writing the code, you realise you totally underestimated the complexity of the problem. :wtf: Today I just hit such a problem.[^] [edit] Found my answer @ http://www.codeproject.com/useritems/ahocorasick.asp[^] ;) [edit] xacc.ide-0.1.1.2 released! :) Download and screenshots -- modified at 17:31 Friday 30th December, 2005
public static List SplitAndKeep(string target) { List list = new List(); StringBuilder builder = new StringBuilder(); for (int i = 0; i < target.Length; i++) { char current = target[i]; switch (current) { case '.': list.Add(builder.ToString()); list.Add("."); builder.Length = 0; break; case ':': if (i < target.Length + 1 && ':' == target[i + 1]) { list.Add(builder.ToString()); list.Add("::"); i++; builder.Length = 0; } else { builder.Append(current); } break; default: builder.AppendFormat(current); break; } } list.Add(builder.ToString()); return list; } Jared Parsons jaredp@beanseed.org http://jaredparsons.blogspot.com/ -- modified at 16:41 Friday 30th December, 2005
-
public static List SplitAndKeep(string target) { List list = new List(); StringBuilder builder = new StringBuilder(); for (int i = 0; i < target.Length; i++) { char current = target[i]; switch (current) { case '.': list.Add(builder.ToString()); list.Add("."); builder.Length = 0; break; case ':': if (i < target.Length + 1 && ':' == target[i + 1]) { list.Add(builder.ToString()); list.Add("::"); i++; builder.Length = 0; } else { builder.Append(current); } break; default: builder.AppendFormat(current); break; } } list.Add(builder.ToString()); return list; } Jared Parsons jaredp@beanseed.org http://jaredparsons.blogspot.com/ -- modified at 16:41 Friday 30th December, 2005
Nice try, but the delimiters can be anything, and any length. :) xacc.ide-0.1.1 released! :) Download and screenshots
-
You know when you sometimes know you want to do something, and you have the whole process visualized elegantly in your mind, and when you get to writing the code, you realise you totally underestimated the complexity of the problem. :wtf: Today I just hit such a problem.[^] [edit] Found my answer @ http://www.codeproject.com/useritems/ahocorasick.asp[^] ;) [edit] xacc.ide-0.1.1.2 released! :) Download and screenshots -- modified at 17:31 Friday 30th December, 2005
I didn't think too much about it, but doesn't (every) standard string searching algorithm be modified to do that? (I mean, search for ":" and "::" and then in the same time split string according to positions of found delimiters (?) Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidy -
I didn't think too much about it, but doesn't (every) standard string searching algorithm be modified to do that? (I mean, search for ":" and "::" and then in the same time split string according to positions of found delimiters (?) Never forget: "Stay kul and happy" (I.A.)
David's thoughts / dnhsoftware.org / MyHTMLTidymy current idea is: create indici for each delimiter in input string, then just walk thru the input string. Even using the best string searching algorithm with this approach, will have a 'high' complexity. Hmmm, this reminds of an article I saw recently on CP (leppie tries the dreaded search). xacc.ide-0.1.1 released! :) Download and screenshots
-
You know when you sometimes know you want to do something, and you have the whole process visualized elegantly in your mind, and when you get to writing the code, you realise you totally underestimated the complexity of the problem. :wtf: Today I just hit such a problem.[^] [edit] Found my answer @ http://www.codeproject.com/useritems/ahocorasick.asp[^] ;) [edit] xacc.ide-0.1.1.2 released! :) Download and screenshots -- modified at 17:31 Friday 30th December, 2005
That isn't so bad to me as when you spend hours coding this sweet routine that makes some control-thingy do something really cool and when you are all done you discover that it was just a method on the control that takes a single parameter... I've been there! I've done *that* and I think I've hated myself ever since. :doh::laugh:
Some assembly required. Code-frog System Architects, Inc.
-
You know when you sometimes know you want to do something, and you have the whole process visualized elegantly in your mind, and when you get to writing the code, you realise you totally underestimated the complexity of the problem. :wtf: Today I just hit such a problem.[^] [edit] Found my answer @ http://www.codeproject.com/useritems/ahocorasick.asp[^] ;) [edit] xacc.ide-0.1.1.2 released! :) Download and screenshots -- modified at 17:31 Friday 30th December, 2005
I think my favorite is when you can't get something to work so you decide to email the authors and ask them about bugs or help. Then you compose a long detailed email describing your problem and the steps you've taken blah blah blah. At which point you discover that your XML file has something slightly mispelled and changing that immediately fixes your problem. Or in a related scenario, you send out the email and then discover your error. Jared Parsons jaredp@beanseed.org http://jaredparsons.blogspot.com/
-
I think my favorite is when you can't get something to work so you decide to email the authors and ask them about bugs or help. Then you compose a long detailed email describing your problem and the steps you've taken blah blah blah. At which point you discover that your XML file has something slightly mispelled and changing that immediately fixes your problem. Or in a related scenario, you send out the email and then discover your error. Jared Parsons jaredp@beanseed.org http://jaredparsons.blogspot.com/
Hey jared...you should add a [^] clicky for your blog link..... Brian Van Beek Inside this room, all of my dreams become realities, and some of my realities become dreams. -Willy Wonka Just started a new blog, yeah! [^]
-
Hey jared...you should add a [^] clicky for your blog link..... Brian Van Beek Inside this room, all of my dreams become realities, and some of my realities become dreams. -Willy Wonka Just started a new blog, yeah! [^]
Thanks. I forgot to add that back in. Jared Parsons jaredp@beanseed.org http://jaredparsons.blogspot.com/[^]
-
You know when you sometimes know you want to do something, and you have the whole process visualized elegantly in your mind, and when you get to writing the code, you realise you totally underestimated the complexity of the problem. :wtf: Today I just hit such a problem.[^] [edit] Found my answer @ http://www.codeproject.com/useritems/ahocorasick.asp[^] ;) [edit] xacc.ide-0.1.1.2 released! :) Download and screenshots -- modified at 17:31 Friday 30th December, 2005
Okay, this is how a dynamic language would solve the problem:
irb(main):003:0> "sys.fun.bar::foo.blah".gsub( /\.|::/, '`\0`' ).split /`/ => ["sys", ".", "fun", ".", "bar", "::", "foo", ".", "blah"]
For those who don't know the language - it's Ruby. Admittedly, the code may be a tad obfuscated, but it sure is a lot easier to grok than an entire page of C# code! Cheers, Diederik -
Okay, this is how a dynamic language would solve the problem:
irb(main):003:0> "sys.fun.bar::foo.blah".gsub( /\.|::/, '`\0`' ).split /`/ => ["sys", ".", "fun", ".", "bar", "::", "foo", ".", "blah"]
For those who don't know the language - it's Ruby. Admittedly, the code may be a tad obfuscated, but it sure is a lot easier to grok than an entire page of C# code! Cheers, DiederikAgain. I am looking for a generic (not generics) solution. But one could always build the Regex string. This could probably done similar in C#. Thanks for the idea, now I just hope .NET RE supports that (char) 0... xacc.ide-0.1.1 released! :) Download and screenshots