In vim:
xxxxxxxxxx
:s/\(test\)/\U\1 file/
In VS Code:
xxxxxxxxxx
# Find
_([a-z])
# Replace
\U$1
xxxxxxxxxx
const snakeToCamelCase = (s) =>
s.toLowerCase().replace(/(_\w)/g, (w) => w.toUpperCase().substr(1));
const str1 = 'learn_javascript';
console.log(snakeToCamelCase(str1));
xxxxxxxxxx
type SnakeToCamelCase<S extends string> =
S extends `${infer T}_${infer U}` ?
`${T}${Capitalize<SnakeToCamelCase<U>>}` :
S
xxxxxxxxxx
import re
def camel_to_snake(s):
return re.sub(r'(?<!^)(?=[A-Z])', '_', s).lower()
original_dict = {
'testId': self.test_id,
'valve': self.valve,
'testType': self.test_type,
'openingPress': self.opening_press,
'closingPress': self.closing_press,
'holdingPress': self.holding_press,
'openingOk': self.opening_ok,
'closingOk': self.closing_ok,
'holdingOk': self.holding_ok,
'testDate': self.test_date,
'userCode': self.user_code
}
snake_case_dict = {camel_to_snake(key): value for key, value in original_dict.items()}
print(snake_case_dict)
xxxxxxxxxx
using System.Text.RegularExpressions;
public class Program
{
public static string ToSnakeCase(string str)
{
return Regex.Replace(str, "[A-Z]", "_$0").ToLower();
}
public static string ToCamelCase(string str)
{
return Regex.Replace(str, "_[a-z]", delegate(Match m) {
return m.ToString().TrimStart('_').ToUpper();
});
}
}