Camel case is a language-independent naming convention in which an identifier name will start with a lowercase letter and each additional word within the name will start uppercase, such as customerName, printInvoice, etc.
Questions tagged [camelcasing]
403 questions
31
votes
3 answers
When should I use camelCase / Camel Case or underscores in PHP naming?
I've been learning PHP and see there is a lot of variability in how people name stuff. I am keen to at least be consistent with myself.
Where should I be using Camel Case and where should I be using underscores?
Thoughts:
Variables / Properties:…

Linz Darlington
- 515
- 1
- 10
- 25
29
votes
5 answers
Convert kebab-case to camelCase with JavaScript
Say I have a function that transforms kebab-case to camelCase:
camelize("my-kebab-string") === 'myKebabString';
I'm almost there, but my code outputs the first letter with uppercase too:
function camelize(str){
let arr = str.split('-');
let…

Robert Hovhannisyan
- 2,938
- 6
- 21
- 43
29
votes
2 answers
Convert CamelCase to under_score_case in php __autoload()
PHP manual suggests to autoload classes like
function __autoload($class_name){
require_once("some_dir/".$class_name.".php");
}
and this approach works fine to load class FooClass saved in the file my_dir/FooClass.php like
class FooClass{
…

P.M
- 2,880
- 3
- 43
- 53
29
votes
6 answers
How to convert not.camel.case to CamelCase in R
In R, I want to convert
t1 <- c('this.text', 'next.text')
"this.text" "next.text"
to
'ThisText' 'NextText'
I have tried
gsub('\\..', '', t1)
But this gives me
"thisext" "nextext"
as it does not replace the letter after the period.
Probably…

Tom Liptrot
- 2,273
- 21
- 23
28
votes
4 answers
How can I convert from underscores to camel case with a regex?
How can I convert names with underscores into camel case names as follows using a single Java/Perl regular expression search and replace?
underscore_variable_name -> underscoreVariableName
UNDERSCORE_VARIABLE_NAME ->…

Jeff Axelrod
- 27,676
- 31
- 147
- 246
28
votes
8 answers
How to convert a camel-case string to dashes in JavaScript?
I want to convert these strings:
fooBar
FooBar
into:
foo-bar
-foo-bar
How would I do this in JavaScript the most elegant and performant way for any given string?

Timo Ernst
- 15,243
- 23
- 104
- 165
23
votes
10 answers
For what reason do we have the lower_case_with_underscores naming convention?
Depending on your interpretation this may or may not be a rhetorical question, but it really baffles me. What sense does this convention make? I understand naming conventions don't necessarily have to have a rhyme or reason behind them, but why…

dav
- 1,211
- 1
- 13
- 19
22
votes
9 answers
linux bash, camel case string to separate by dash
Is there a way to convert something like this:
MyDirectoryFileLine
to
my-directory-file-line
I found some ways to convert all letters to uppercase or lowercase, but not in that way; any ideas?

armandfp
- 1,059
- 1
- 9
- 18
22
votes
4 answers
Convert a String to Modified Camel Case in Java or Title Case as is otherwise called
I want to convert any string to modified Camel case or Title case using some predefined libraries than writing my own functions.
For example "HI tHiS is SomE Statement" to "Hi This Is Some Statement"
Regex or any standard library will help me.
I…

takrishna
- 4,884
- 3
- 18
- 35
20
votes
1 answer
Single letter words in camelCase, what is a standard for handling these?
I'm trying to group together an object's vertex X components in a vector, like structure of array style.
Naturally this is the way.
Vec xComponents; or Vec xVals; or simply Vec x;
However sometimes I want to specify in the id what x components…

Thomas
- 6,032
- 6
- 41
- 79
20
votes
5 answers
Awk/sed script to convert a file from camelCase to underscores
I want to convert several files in a project from camelCase to underscore_case.
I would like to have a onliner that only needs the filename to work.

Corentin Peuvrel
- 310
- 1
- 2
- 9
19
votes
1 answer
Camel casing hyphenated English words (e.g. re-render)
Typically if you're converting a string of words to camel case you capitalise only the first letter of every word (bar the first word).
How does this apply to hyphenated words like re-render?
Something deep inside me wants it to be rerender or…

Simon Hartcher
- 3,400
- 3
- 30
- 34
19
votes
2 answers
When syncing with an underscored backend, convert to CamelCase for use in JavaScript?
TL/DR: What's a good way to use an underscored naming convention serverside (RoR) with a camelCased naming convention clientside (JS)
Server-side programming environments like Ruby on Rails use underscored variables. Conventionally, JavaScript uses…

Geoff
- 9,470
- 13
- 52
- 67
18
votes
2 answers
Changing parts of CamelCase words in vim
Using vim, I find cw very handy for changing an entire word. Vim's separation of motion commands and action verbs makes for very powerful combinations. I just now had to change DefaultHandler to ContentHandler. I naturally thought of it as…

Ned Batchelder
- 364,293
- 75
- 561
- 662
18
votes
3 answers
camelCase to dash - two capitals next to each other
I'm using this function to convert CamelCase to dashed string:
function camel2dashed($className) {
return strtolower(preg_replace('/([^A-Z-])([A-Z])/', '$1-$2', $className));
}
it kinda works but theres problem when I have for ex. this string:…

simPod
- 11,498
- 17
- 86
- 139