我发现了这个类似的问题,但它没有回答我的问题,大写字母拆分.
我有一个骆驼案的字符串.我想在每个大写字母中分解该字符串,如下所示.
$str = 'CamelCase'; // array('Camel', 'Case');
Run Code Online (Sandbox Code Playgroud)
我到目前为止:
$parts = preg_split('/(?=[A-Z])/', 'CamelCase');
Run Code Online (Sandbox Code Playgroud)
但是结果数组总是在开头时以空值结束!$parts看起来像这样
$parts = array('', 'Camel', 'Case');
Run Code Online (Sandbox Code Playgroud)
如何摆脱数组开头的空值?
我在画布上绘制不同颜色的方块,固定大小为50px x 50px.
我已经成功地为这些彩色方块添加了5px的透明内部笔划,但它看起来像我做的那样大规模过度杀伤.
ctx.fillStyle = this.color;
ctx.fillRect(this.x, this.y, engine.cellSize, engine.cellSize);
ctx.fillStyle = 'rgba(0, 0, 0, 0.2)';
ctx.fillRect(this.x, this.y, engine.cellSize, engine.cellSize);
ctx.fillStyle = this.color;
ctx.fillRect(this.x + 5, this.y + 5, engine.cellSize - 10, engine.cellSize - 10);
Run Code Online (Sandbox Code Playgroud)
有没有比绘制3个单独的矩形更好的方法来实现我追求的目标?