There are quite a few instances where string operations in C# seem slightly verbose. So, I had a play around with extension methods the other day to see if I could come up with some alternate ways of doing some pretty standard operations but with a touch more syntactic sugar sprinkled on the top.
For example, rather than using string.IsNullOrEmpty it makes much more sense to me to call IsNullOrEmpty on the string you want to check instead:
// Checking for a null or empty string in C#
if (string.IsNullOrEmpty(foo)) {
...
}
// versus
if (foo.IsNullOrEmpty()) {
...
}
Also, I thought it would be nicer if you could call some of the static Regex methods directly on string objects:
// Instead of this
if (Regex.IsMatch(foo, @"[a-zA-Z]+")) {
...
}
// You could just do this
if (foo.IsMatch(@"[a-zA-Z]+")) {
...
}
I have created a gist of these methods, plus a few others:
http://gist.github.com/111696
Are there any other string operations that you think should be included? If you have any suggestions, etc. please be sure to comment.
Posted in
asp.net,
c# at July 20th, 2009.
No Comments.
So, you are using the e text editor and try to run a bundle only to be confronted with the following:
ruby: no such file to load — ubygems (LoadError) ruby: no such file to load — ubygems (LoadError)
After doing some digging it turns out the cause is the RUBYOPT=-rubygems environment variable that is set by the Windows one-click Ruby installer. Now, if you have not got rubygems installed you might be able to get away with simply unsetting the RUBYOPT environment variable (although YMMV).
However, as e text editor makes use of Ruby via Cygwin, another solution is to modify your .bashrc file:
Try this:
Go to the cygwin bash prompt. If you don't know how to get there, use Start -> Run -> c:\cygwin\cygwin.bat.
Type:
echo unset RUBYOPT >> .bashrc
Type:
. .bashrc
Type:
irb
If you see:
irb(main):001:0>
You should be good to go.
But what worked for me – and I don’t know whether this has anything to do with me having Ruby installed under Windows and under Cygwin – was making the same changes to .bashrc outlined above to my .profile script (so simply replace .bashrc with .profile in the quoted text above).
Hopefully at least one of these methods should work for you.
Posted in
devtools at July 6th, 2009.
1 Comment.