VBScript – CamelCase Function

One of the things that is often used in the JavaScript Prototype library is the camelize function which camel-cases the specified string. Unfortunately, just as this function doesn’t exist natively in JavaScript, it also doesn’t in VBScript. If you do need an equivalent function to that which is available in the Prototype library, you can use the following function definition:

Public Function CamelCase(str)
  Dim arr, i
  arr = Split(str, "-")
  For i = LBound(arr) + 1 To UBound(arr)
    arr(i) = UCase(Left(arr(i), 1)) & Mid(arr(i), 2)
  CamelCase = Join(arr, "")
End Function

To use this function, simply pass the string that you want to be camel-cased, and the modified string will be returned:

MsgBox CamelCase("border-color-left")

VBScript To JavaScript – Space Function

In VBScript, there is a space function which takes an integer and returns a string with the specified number of spaces. At times, you may need such a function to make you text look neat while working with a monospace font. Here is the code that you could use to define your own space function in JavaScript:

function space(num) {
  return new Array(num + 1).join(" ");

Basically, the space function creates an array of a length that is one more than the number that is specified. After that, the array of undefined values is joined together with the delimiter of a space (thus the reason for using num + 1 to ensure the correct amount of spaces). Finally, this string of spaces is returned.