camelcasing

Converting any string into camel case

半世苍凉 提交于 2019-11-26 14:14:49
How can I convert a string into camel case using javascript regex? EquipmentClass name or Equipment className or equipment class name or Equipment Class Name should all become: equipmentClassName . CMS Looking at your code, you can achieve it with only two replace calls: function camelize(str) { return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) { return index == 0 ? word.toLowerCase() : word.toUpperCase(); }).replace(/\s+/g, ''); } camelize("EquipmentClass name"); camelize("Equipment className"); camelize("equipment class name"); camelize("Equipment Class Name"); // all output

RegEx to split camelCase or TitleCase (advanced)

大城市里の小女人 提交于 2019-11-26 11:43:06
I found a brilliant RegEx to extract the part of a camelCase or TitleCase expression. (?<!^)(?=[A-Z]) It works as expected: value -> value camelValue -> camel / Value TitleValue -> Title / Value For example with Java: String s = "loremIpsum"; words = s.split("(?<!^)(?=[A-Z])"); //words equals words = new String[]{"lorem","Ipsum"} My problem is that it does not work in some cases: Case 1: VALUE -> V / A / L / U / E Case 2: eclipseRCPExt -> eclipse / R / C / P / Ext To my mind, the result shoud be: Case 1: VALUE Case 2: eclipse / RCP / Ext In other words, given n uppercase chars: if the n chars

How do I convert CamelCase into human-readable names in Java?

风格不统一 提交于 2019-11-26 11:05:36
I'd like to write a method that converts CamelCase into a human-readable name. Here's the test case: public void testSplitCamelCase() { assertEquals("lowercase", splitCamelCase("lowercase")); assertEquals("Class", splitCamelCase("Class")); assertEquals("My Class", splitCamelCase("MyClass")); assertEquals("HTML", splitCamelCase("HTML")); assertEquals("PDF Loader", splitCamelCase("PDFLoader")); assertEquals("A String", splitCamelCase("AString")); assertEquals("Simple XML Parser", splitCamelCase("SimpleXMLParser")); assertEquals("GL 11 Version", splitCamelCase("GL11Version")); }

RegEx to split camelCase or TitleCase (advanced)

橙三吉。 提交于 2019-11-26 05:50:33
问题 I found a brilliant RegEx to extract the part of a camelCase or TitleCase expression. (?<!^)(?=[A-Z]) It works as expected: value -> value camelValue -> camel / Value TitleValue -> Title / Value For example with Java: String s = \"loremIpsum\"; words = s.split(\"(?<!^)(?=[A-Z])\"); //words equals words = new String[]{\"lorem\",\"Ipsum\"} My problem is that it does not work in some cases: Case 1: VALUE -> V / A / L / U / E Case 2: eclipseRCPExt -> eclipse / R / C / P / Ext To my mind, the

Converting any string into camel case

可紊 提交于 2019-11-26 03:35:33
问题 How can I convert a string into camel case using javascript regex? EquipmentClass name or Equipment className or equipment class name or Equipment Class Name should all become: equipmentClassName . 回答1: Looking at your code, you can achieve it with only two replace calls: function camelize(str) { return str.replace(/(?:^\w|[A-Z]|\b\w)/g, function(word, index) { return index == 0 ? word.toLowerCase() : word.toUpperCase(); }).replace(/\s+/g, ''); } camelize("EquipmentClass name"); camelize(

How do I convert CamelCase into human-readable names in Java?

旧城冷巷雨未停 提交于 2019-11-26 02:17:08
问题 I\'d like to write a method that converts CamelCase into a human-readable name. Here\'s the test case: public void testSplitCamelCase() { assertEquals(\"lowercase\", splitCamelCase(\"lowercase\")); assertEquals(\"Class\", splitCamelCase(\"Class\")); assertEquals(\"My Class\", splitCamelCase(\"MyClass\")); assertEquals(\"HTML\", splitCamelCase(\"HTML\")); assertEquals(\"PDF Loader\", splitCamelCase(\"PDFLoader\")); assertEquals(\"A String\", splitCamelCase(\"AString\")); assertEquals(\"Simple

Elegant Python function to convert CamelCase to snake_case?

被刻印的时光 ゝ 提交于 2019-11-26 01:50:21
问题 This post is a Community Wiki . Edit existing answers to improve this post. It is not currently accepting new answers. Example: >>> convert(\'CamelCase\') \'camel_case\' 回答1: This is pretty thorough: def convert(name): s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name) return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower() Works with all these (and doesn't harm already-un-cameled versions): >>> convert('CamelCase') 'camel_case' >>> convert('CamelCamelCase') 'camel_camel_case' >>> convert(