Break Case Function for LibreOffice Calc

BREAKCASE() Description

The function BREAKCASE() is designed to break text with separators into separate words, that is, the function returns the result in the following format: "break case function".

Break Case first breaks a string of words separated by a space, hyphen, or underscore into individual elements, then converts all words to lowercase and combines them into a single sentence with an empty separator (" ").

The BREAKCASE() function can be useful in programming to convert variable names according to accepted code writing conventions (coding conventions).

BASIC code for function Break Case

Here is the macro code to create a custom function that can break text into individual words (Break Case) in LibreOffice Calc.

Open the menu Tools - Macros - Edit Macros..., select Module1 and copy the following text into the module:

Function BreakCase(ByVal str As String) As String
  Dim FCalc As Object
  FCalc = CreateUnoService("")
  str = Replace(str,"-"," ")
  str = Replace(str,"_"," ")  
  str = FCalc.callFunction("TRIM", Array(str))  
  str = FCalc.callFunction("REGEX", Array(str,"([:lower:])([:upper:])","$1 $2","g"))
  BreakCase = LCase(str)        
End Function

Then close Macro Editor, return to LibreOffice Calc and use our new function in any cell.