一、背景
使用Python实现字符串字母全大写下划线形式转驼峰形式。
二、代码实现
def change():
str = "{\"ABC\":{\"ABC_DE\":\"\",\"EF\":\"2024-02-04 10:15:15\",\"FGH_IKG_MH\":\"\",\"ABC_DE\":{\"ABC\":[{\"ABIE_IJND_DKNF\":\"2024-02-04 10:19:51\",\"KDJF_IDF\":\"34567898765456789876567898765\",\"DFADF_IDFJD_DFD\":null,\"DJFD_KDF\":\"\",\"IED_IDNFD_DFD\":null,\"KDFDA_IDFDF_DFADF\":null,\"DFDADFA_IDFADFA\":\"111\"}]}}}"
str = str.lower()
start = 0
str1 = str
count = str.count('_')
for i in range(count):
str = str1
index = str.find("_", start)
str1 = str[0: index] + str[index+1].upper() + str[index+2:]
start = str1.find("_", start)
print(str1)
三、方法
str.find(sub[, start[, end]])