Thursday, August 30, 2007

Simple function to split camelCase words

The phrase "camel case" is used to describe a common method of naming variables, properties, and methods in a programming language.

It is useful for stringing several words together, while maintaining readability.  (More here)

If you ever have the need to split apart the words in a camel case word, here's just about the easiest way to do it (shown in both VB.NET and C#):

SplitCamelCase() - VB

Function SplitCamelCase(ByVal Source As String) As String()
    Return Regex.Split(Source, "(?<!^)(?=[A-Z])")
End Function

SplitCamelCase() - C#

string[] SplitCamelCase(string source) {
    return Regex.Split(source, @"(?<!^)(?=[A-Z])");
}

 

0 Comments:

Post a Comment

<< Home