草庐IT

camelcasing

全部标签

java - 用于在 java 中将 CamelCase 转换为 camel_case 的正则表达式

我理解为什么在使用正则表达式将FooBar之类的字符串转换为Foo_Bar时没有给出所需的输出,而是给出了Foo_Bar_。我可以用String.substringsubstring(0,string.length()-2)做一些事情,或者只是替换最后一个字符,但我认为这种情况有更好的解决方案。代码如下:Stringregex="([A-Z][a-z]+)";Stringreplacement="$1_";"CamelCaseToSomethingElse".replaceAll(regex,replacement);/*outputs:Camel_Case_To_Something_

python - 如果首选 names_with_underscores,为什么使用 unittest2 方法 camelCase?

这是PEP8中描述函数名称的部分:Functionnamesshouldbelowercase,withwordsseparatedbyunderscoresasnecessarytoimprovereadability.mixedCaseisallowedonlyincontextswherethat'salreadytheprevailingstyle他们为什么不更改函数名称?这对于没有保持向后兼容性的Python3尤其重要。 最佳答案 来自unittest2website:unittest2isabackportofthene

ruby-on-rails - 在 Ruby 中将句子转换为 Camelcase

这个问题在这里已经有了答案:Convertingstringfromsnake_casetoCamelCaseinRuby(10个答案)关闭9年前。这看起来简单得离谱,但我在任何地方都找不到将句子字符串/带连字符的字符串转换为驼峰式转换的方法。Ex:'thisisasentence'=>'thisIsASentence''my-name'=>'myName'使用正则表达式似乎有些矫枉过正。什么是最好的方法?

php - 在 PHP 中将 UpperCase CamelCase 分解为 Upper Case Camel Case

现在,我正在通过拆分、切片和内爆来实现它:$exploded=implode('',array_slice(preg_split('/(?=[A-Z])/','ThisIsATest'),1));//$exploded="ThisIsATest"更漂亮的版本:$capital_split=preg_split('/(?=[A-Z])/','ThisIsATest');$blank_first_ignored=array_slice($capital_split,1);$exploded=implode('',$blank_first_ignored);但是,问题是当您输入类似'Some

php - 在 Laravel Eloquent 模型中,我们是否使用 camelCase 调用表字段名称,即使它们在数据库中包含下划线?

在数据库中,假设我在我的用户表中有这些字段:name、favorite_color、created_at等...使用Eloquent保存:1:$user=newUser;$user->name="John";$user->favorite_color='blue';//Noticetheunderscore$user->save();2:$user=newUser;$user->name="John";$user->favoriteColor='blue';//camelCase$user->save();以上哪一项是正确的? 最佳答案

python - find_all 带有 BeautifulSoup 4 的 camelCase 标签名称

我正在尝试使用BeautifulSoup4.4.0抓取一个xml文件,该文件的标签名称采用驼峰命名法,而find_all似乎无法找到它们。示例代码:frombs4importBeautifulSoupxml="""world"""soup=BeautifulSoup(xml,"lxml")forxinsoup.find_all("hello"):printxxml2=""":-)"""soup=BeautifulSoup(xml2,"lxml")forxinsoup.find_all("helloWorld"):printx我得到的输出是:$pythonsoup_test.pyworl

ios - 在 Swift 中将 CamelCase 字符串分隔为空格分隔的单词

我想将CamelCase字符串分隔成新字符串中以空格分隔的单词。这是我目前所拥有的:varcamelCaps:String{guardself.count>0else{returnself}varnewString:String=""letuppercase=CharacterSet.uppercaseLettersletfirst=self.unicodeScalars.first!newString.append(Character(first))forscalarinself.unicodeScalars.dropFirst(){ifuppercase.contains(scal

c# - 仅当未在 Json.Net 中明确设置 PropertyName 时才使用 CamelCase?

我正在为我的网站使用Json.Net。我希望序列化程序在默认情况下以驼峰命名法序列化属性名称。我不希望它更改我手动分配的属性名称。我有以下代码:publicclassTestClass{publicstringNormalProperty{get;set;}[JsonProperty(PropertyName="CustomName")]publicstringConfiguredProperty{get;set;}}publicvoidExperiment(){vardata=newTestClass{NormalProperty=null,ConfiguredProperty=nu

c# - 拆分 CamelCase

这都是asp.netc#。我有一个枚举publicenumControlSelectionType{NotApplicable=1,SingleSelectRadioButtons=2,SingleSelectDropDownList=3,MultiSelectCheckBox=4,MultiSelectListBox=5}这个数值存储在我的数据库中。我在数据网格中显示此值。ID对用户没有任何意义,因此我已将绑定(bind)列更改为具有以下内容的模板列。这样好多了...但是,如果我可以在Enum周围放置一个简单的函数以按Camel大小写拆分它,以便单词在数据网格中很好地包装,那就太好了

c# - 对象及其子对象上的 Web API 2 : how to return JSON with camelCased property names,

更新谢谢大家的回答。我在一个新项目上,看起来我终于弄清楚了这个问题:看起来实际上应该归咎于以下代码:publicstaticHttpResponseMessageGetHttpSuccessResponse(objectresponse,HttpStatusCodecode=HttpStatusCode.OK){returnnewHttpResponseMessage(){StatusCode=code,Content=response!=null?newJsonContent(response):null};}其他地方...publicJsonContent(objectobj){v