Quantcast
Channel: User user2023861 - Code Review Stack Exchange
Browsing index pages (35 articles)
↧

Answer by user2023861 for Convert XML to CSV

You can do it with a series of Regex.Replaces:// 1) Replace closing and opening tags with commas.// Include quotes in case any values have commas in them.var result = Regex.Replace(input,...

View Article


Answer by user2023861 for Function to compare objects based on type enums

Your outer switch statement has 9 cases (and one default). If you take advantage of polymorphism, you can split this out into 9 classes with no need for some default handler. Here's some information...

View Article


Answer by user2023861 for Extracting Excel data out of an existing Excel file

Two quick points:First: Make sure you're cleaning up your Interop objects properly. It's not easy. See here for more. The first answer has good advice: never use two dots with COM objects. Many of your...

View Article

Answer by user2023861 for A more efficient way of extracting a name from a...

Here's a simple Regex to pull out the CN value:CN=([^,]*),You can use this C# code to get the value:string CN = Regex.Replace(input, @"CN=([^,]*),", "$1");Here are the important points:I'm assuming you...

View Article

Answer by user2023861 for Parsing data from text with repeating blocks

Your methods are too big and are doing too much. ParseDebugListResponse is responsible for finding the backend boundaries, splitting the response into backend objects, determining what each line is,...

View Article


Answer by user2023861 for Swapping characters pairs in a string

Finally, an excuse to use the Zip extension method:private static string StringSwap2(string stringToSwap){ if ((stringToSwap.Length % 2).Equals(1)) { stringToSwap += ""; } var evens =...

View Article

Answer by user2023861 for Puzzle Packing Box Z optimisation

This is not an answer about your algorithm but a couple of performance comments that wouldn't fit in the ongoing comment discussion.I'm guessing that your deeply nested loops are taking up the bulk of...

View Article

Answer by user2023861 for Top Python badged users from NYC

In my opinion, your where clauses take up too much vertical space and can be made more maintainable. Compare what you have with this:where b.name = N'python' and b.class = 3 -- 1 is gold, 2: silver, 3:...

View Article


Answer by user2023861 for FizzBuzz in T-SQL

Here's a pretty succinct way to do it. I use a recursive common-table expression to fill in a table of integers from 1 to 100.with tbl (idx)as( select 1 union all select idx + 1 from tbl where idx <...

View Article


Answer by user2023861 for Simple foreach adding to a list

Just use the Concatenation method. That's really what you're doing. You can also use the List constructor that takes an IEnumerable.var soonestDrawDateModel = new List<SoonestDrawDateModel>(...

View Article

Answer by user2023861 for Converting a 12 hour time string to a 24 hour time...

Here's how to parse dates and times using built-in .Net libraries:static void Main(){ string strTime = "01:00:10AM"; DateTime time; if (DateTime.TryParseExact(strTime, "hh:mm:sstt", null,...

View Article

Answer by user2023861 for Implementing a thread safe log class with simple...

A comment about your Log(string) method. The lock keyword is just syntactic sugar for a call to the Monitor class. See here. Here is what lock becomes:bool lockWasTaken = false;var temp = obj;try {...

View Article

Answer by user2023861 for Demonstration of inheritance with some shapes

Your code doesn't benefit from the use of inheritance. You can remove all references to IShape without losing anything. If you had an illustrator class that accepted IShape objects, then you'd have...

View Article


Answer by user2023861 for Stack implementation in C#

Going off your question about pushing zeroes onto the stack, another user mentioned that you should keep an index into the stack to remember where to push and pop. I've updated your code only...

View Article

Answer by user2023861 for Find the largest odd number (follow-up code)

You can do this without storing the inputs and looping through them afterwards. You only need to remember whether or not an odd number was entered and which one is the largest. My Python is weak so...

View Article


Answer by user2023861 for SQL query to select most recent version

You can use a sub-query:declare @tbl table ( id INT, effective DATE, points INT)INSERT INTO @tblVALUES (1, '1/1/2015', 123), (1, '2/1/2015', 234), (1, '3/1/2015', 345), (2, '4/1/2015', 123), (2,...

View Article

Answer by user2023861 for Sorting a list of first names from a text file

Here's a way to do it in one line of Linq code:int score = System.IO.File.ReadAllLines(ConfigurationManager.AppSettings["LocationOfNamesFile"]) .SelectMany(s => s.Split(',')) .OrderBy(b => b)...

View Article


Answer by user2023861 for String reversal, capitalize vowels, lowercase...

You can make use of char static methods to do a lot of the work for you. Also, there's no need to memorize the ASCII values of vowels. Just use the vowels themselves.static string Problem(string arg){...

View Article

Answer by user2023861 for Matching any certain selection of inputs

I'd suggest that you simplify. Imagine you're a junior programmer and you are asked to edit this abomination (or the one in the accepted answer) in order to add support for inputs of the type 10cm and...

View Article

Answer by user2023861 for Given two int values, return the one closer to 10

A little math can shorten this. Take the average of the two numbers. If the average is higher than 10, that means the higher number is pulling up the average more than the lower number is pulling it...

View Article
Browsing index pages (35 articles)


Latest Images