# Monday, December 20, 2004
« Tip of the day - Javascript - Getting th... | Main | Tip of the Day: Debugging Javascript in ... »

Say what you will about VB, it does have some wrappers for some neat functions. One of my favorites is the Split function. Essentially, it takes a string, a parse character parameter, and returns a string array of the items. For example, it might look like string[] mystring = Split(myCommaDelimitedString,”,”);

So here's what the code looks like:

  /// <summary>
  /// Replacement in C# of the VB.Net split function
  /// </summary>
  /// <param name="baseString">string to parse</param>
  /// <param name="splitChar">chanracter to parse with </param>
  /// <returns></returns>
  public static string[] Split(string baseString, string splitChar)
  {
   char[] sep = {(splitChar.ToCharArray())[0]};
   return baseString.Split(sep);
  }

Now, I know you can use the string object's split functionality to do the same thing. However, those coming out of the VB world will appreciate the encapsulation, as well as never having to remember the syntax for pre-defining a character array.

 

Tuesday, April 24, 2007 3:52:45 AM (GMT Daylight Time, UTC+01:00)
Thank you.
Vijayan
Comments are closed.