驼峰格式和下划线格式转换_translation between camel and snake format
#1 驼峰转下划线格式
这个我一开始找了找现成的方法,比如这里:http://www.iteye.com/topic/1118302,但一眼看过去就非常的麻烦,难道这个操作要写好几十行代码么,我可很懒哦。
后来想到用正则直接处理。
>> $className = "HelloWorldRuby";
>> $snakeTableName = preg_replace('/(?<!\b)(?=[A-Z])/', "_", $className);
>> print_r($snakeTableName);
Hello_World_Ruby
>> $snakeTableNameLower = strtolower($snakeTableName);
>> print_r($snakeTableNameLower);
hello_world_ruby
1.9.3p194 :022 > className = "HelloWorldRuby"
=> "HelloWorldRuby"
1.9.3p194 :023 > #classNameSnake = className.gsub(/(?<!\b)(?=[A-Z])/, "_"); #=> Error ruby的逆序环视支持不好
1.9.3p194 :024 > classNameSnake = className.gsub(/(?=[A-Z])/, "_")
=> "_Hello_World_Ruby"
1.9.3p194 :025 > classNameSnakeLower = classNameSnake.downcase[1..-1]
=> "hello_world_ruby"
蛇行转驼峰格式
这个其实就比较好做了,因为下划线作为分隔符号,可以方便的分出来。
但如果用正则的话,怎么做呢:
>> $s = "hello_world_ruby";
>> $s2 = preg_replace('/(?:^|_)([a-z])/e', "strtoupper('\\1')", $s);
>> print_r($s2)
HelloWorldRuby
1.9.3p194 :055 > s = "hello_world_ruby"
=> "hello_world_ruby"
1.9.3p194 :056 > s.gsub(/(?:^|_)([a-z])/e, '\1')
=> "helloworldruby"
ruby中的替换没有/e选项,php和perl都有。
所以这里就不知道替换的时候如何对分组应用函数了(或者用ruby的话是应用block)?
谁知道的,请告知下吧!谢谢!
分享到:
相关推荐
from camel_converter import to_snake snake = to_snake ( "myString" ) 这会将myString转换为my_string 要将蛇皮转换为骆驼皮: from camel_converter import to_camel camel = to_camel ( "my_string" ) 这...
Camel3 Camel6函数等matlab源代码
camel-snake-kebab, 用于字案转换的Clojure [Script] 库 camel-snake-kebab用于字案转换的Clojure [Script] 库。示例(use 'camel-snake-kebab.core)(->camelCase 'flux-capacitor);
输入: GeeksForGeeks输出: geeks_for_geeks输入: ThisIsInCamelCase输出: this_is_in_camel_case 让我们看看完成此任务的不同方法。 方法#1:朴素方法 这是一种将驼峰式大小写转换为蛇式大小写的简单实现。...
Camel_SNAKE-烤肉串 用于单词大小写转换的 Python 库。 这个库是@qerub的一个端口。 它在 PyPI 上可用,可以安装 pip install --user camel_snake_kebab 它使用 Python 2.7 和 Python 3.4 进行了测试。 例子 >>...
蛇骆驼开关 在蛇和骆驼之间切换 默认键是 option+s
Laravel开发-snake2camel 用于通过camelcase获取和设置snakecase中模型字段的laravel框架包
利用遗传算法的全局寻优原理,来找最优值;流程是1、初始化种群 ->2、计算适应值->3、选择复制->(4、交叉->5、变异->2、计算适应值->3、选择复制-)括号中做迭代
matlab的6驼峰功能的实现六驼峰CAMEL功能说明:外形尺寸:2左边的图显示了在其推荐的输入域的六驼峰骆驼功能,并且在右边的图显示了该结构域的仅一部分,以允许更容易地观看的功能键的特性。该函数有六个地方很小,...
基于camel的配置文件实现接口适配,通过apache camel 通过更改配置文件,来实现各种接口的适配,包括Websocket,http,socket,Webserivce,数据库,定时任务
该文档来自阿帕奇2015中国路演。姜宁发表了题为“我和Apache Camel这些年/Years of Apache Camel and I”的主题演讲,欢迎下载!
apache_camel_tutorial
It then shows you the entire lifecycle and goes in depth on how to test, deal with errors, scale, deploy, and even monitor your app—details you can find only in the Camel code itself. Written by the...
It then shows you the entire lifecycle and goes in depth on how to test, deal with errors, scale, deploy, and even monitor your app—details you can find only in the Camel code itself. Written by the...
JavaScript 中字符串和对象键的下划线到驼峰式转换(反之亦然)。 转换对象键时,它将遍历结构,沿途转换任何嵌套对象(或嵌套对象数组)。 便于在 JavaScript 和 Ruby/Rails API 之间转换 JSON。 需要从灵感和...
ApacheCamel-JDBC Apache Camel JDBC组件 代码样例Demo
驼峰翻译 这是什么 一个基于Chrome的翻译插件 有什么功能 发布翻译 多语言支持 划词翻译 暗示 驼峰识别 下划线识别 中划线识别
key_map ( "<leader>c" )def toggle_snake_case_camel_case (): """ take the word under the cursor and toggle it between snake-case and camel-case """ word = snake . get_word () # is it snake case? if "_...
:snake: :将驼峰化的字符串转换为`snake_case` 安装 $ pip install decamelize 为什么? 将CamelCase变成non_camel_case 干净而专心 积极维护 用法 import decamelize print ( decamelize . convert ( "CamelCase...
After briefly introducing the key features and core concepts of Camel, the book will take you through all the important features and components, starting with routing and processors. You will learn ...