Saturday, 17 January 2015

String vs string in C#

What's the difference between String and string in C#?

I don't recall why I started asking this question at interviews, I don't actually think it tells me anything other than whether the interviewee knows the difference between string and String and now I find that I can't stop myself from asking it.

I just want somebody to give me the right answer, one person, just one person would do.

Thus far, I've asked this question at eight interviews, yes, I know a pitifully small sample size, but still I would've expected to have found somebody who was aware of the difference or lack thereof. 

It's not like all interviewees have been fresh out of uni, in fact only one has been.

By far the most common answer (~90%) is :

String is class

For those of you wondering, what the difference is: There is none

What a bastard, right?

string is just an alias of System.String.

Friday, 2 January 2015

Regular Expression Find and Replace in Notepad++

So today I found myself editing a page from our internal Wiki and the formatting was completely and utterly up: Headings were all wrong, some at level 2, others at level 3 and quite a few other things were wrong as well.

I copied and pasted the page to Notepad++ and decided to use Find and Replace, but how could I use Regular Expressions to find and replace.

Simple, it turns out that all that's needed is to use capturing groups.

Input Text:
1. == Section 1 ==
....
2. == Section 2 ==
....
3. === Section 3 ===
....
4. == Section 4 ==
Desired Output Text:
1. === Section 1 ===
....
2. === Section 2 ===
....
3. === Section 3 ===
....
4. === Section 4 ===
So this is the regular expression I used:
Find Regular Expression Explanation:
Replace Regular Expression Explanation:

Add = to the end of each capturing group

Hope this helps