Question: I'd like to write a simple C# app to collect the output of a Zebra printer's magnetic card reader. (Model RW420) My only interface to the device is USB. The CPCL language specifies an `MCR` command for this purpose, but I cannot figure out how to issue this command to the printer via .NET. Neither the online documentation nor support staff can tell me. Does anyone have an idea?

Answer: 
This can be concisely done with regex lookahead ([live demo](http://jsfiddle.net/7rpLz/)):

```
function splitCamelCaseToString(s) {
    return s.split(/(?=[A-Z])/).join(' ');
}

```

(I thought that the `g` (global) flag was necessary, but oddly enough, it isn't in this particular case.)

Using lookahead with `split` ensures that the matched capital letter is not consumed and avoids dealing with a leading space if UpperCamelCase is something you need to deal with. To capitalize the first letter of each, you can use:

```
function splitCamelCaseToString(s) {
    return s.split(/(?=[A-Z])/).map(function(p) {
        return p.charAt(0).toUpperCase() + p.slice(1);
    }).join(' ');
}

```

The `map` array method is an ES5 feature, but you can still use it in older browsers with [some code from MDC](http://jsfiddle.net/7rpLz/). Alternatively, you can iterate over the array elements using a `for` loop.
```
function spacecamel(s){
    return s.replace(/([a-z])([A-Z])/g, '$1 $2');
}

```

spacecamel('somethingLikeThis')

// returned value: something Like This