8Trends

Camel Case to Spaces or Underscore

Recently while working on a project, I found I needed to convert camelcase strings to space-separated strings. This same technique will work if you want to convert camelcase to underscore separation as well.

Camel case is frequently used in programming and data storage. Here are a couple of ways to convert it. As usual, feel free to leave better methods in the comments below.

CamelCase to Underscore–

//example: parseServerInfo to parse_server_info
$string = preg_replace(‘/(?<=\\w)(?=[A-Z])/',"_$1", $string);
$string = strtolower($string);

CamelCase to Spaces–

//example:BachJS to Bach J S
$string = preg_replace(‘/(?<=\\w)(?=[A-Z])/’,” $1″, $string);
$string = trim($string);

Share to:



Camel Case to Spaces or Underscore

Date Time :
Author :
Labels :



Related Posts

Rekomendasi

1 comments
avatar Blogger Admin

3 December 2017 at 14:50

BlueHost is the best website hosting provider for any hosting services you require.

Comment!