Search

Tutorials, tips&tricks, snippets..

#KISS: KEEP IT SIMPLE, STUPID!

Category

Uncategoriezed

Extension Methods #5: check if object has a method

We have a lot of confortable methods ready to use in our .NET objects and this is wonderful: just think for example the method .toString()! How much do we use it? But, sometimes, these methods aren’t enough and we need to create others on our own.

Continue reading “Extension Methods #5: check if object has a method”

Advertisements

C#: Splitting a string with another string as delimiter

This is for split string with a char as delimiter:

string input = "hello_world_this_is_me";
var output = input.Split("_");

For split it with a string as delimeter:

string input = "hello_:_world_:_this_:_is_:_me";
var output = input.Split(new string[] { "_:_" }, StringSplitOptions.None);

The second parameter can be StringSplitOptions.None or StringSplitOptions.RemoveEmptyEntries: with the value StringSplitOptions.RemoveEmptyEntries, the return value does not include array elements that contain an empty string.

Powered by WordPress.com.

Up ↑