Ad
Code
Diff
  • def to_camel_case(text: str):
        split_chars = "-_"
        # loop over each character above
        for split_char in split_chars:
            split_parts = text.split(split_char)
            # skip if there was nothing to split on
            if len(split_parts) == 1:
                continue
            parts = []
            # break up the string in to it's parts
            for i, item in enumerate(split_parts):
                # save the first part but don't change the case of the first letter
                if i == 0:
                    parts.append(item)
                    continue
                parts.append(f"{item[0].upper()}{item[1:]}")
            # join the parts and overwrite the text variable for the next loop
            text = "".join(parts)
        return text
    • def to_camel_case(text):
    • k = text.split("-")
    • p = case_loop(k)
    • j = p.split("_")
    • m = case_loop(j)
    • return m
    • def case_loop(k):
    • p = []
    • for i,item in enumerate(k):
    • if i == 0:
    • p.append(item)
    • def to_camel_case(text: str):
    • split_chars = "-_"
    • # loop over each character above
    • for split_char in split_chars:
    • split_parts = text.split(split_char)
    • # skip if there was nothing to split on
    • if len(split_parts) == 1:
    • continue
    • # print(i,item)
    • a = item[0].upper()
    • b = item[1:]
    • c = f"{a}{b}"
    • p.append(c)
    • d = "".join(p)
    • return d
    • parts = []
    • # break up the string in to it's parts
    • for i, item in enumerate(split_parts):
    • # save the first part but don't change the case of the first letter
    • if i == 0:
    • parts.append(item)
    • continue
    • parts.append(f"{item[0].upper()}{item[1:]}")
    • # join the parts and overwrite the text variable for the next loop
    • text = "".join(parts)
    • return text