Advertisement
TShiva

camel_case

May 30th, 2017
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. def to_camel_case(text):
  2.     if len(text) >= 1:
  3.  
  4.         i=0
  5.         while i < len(text):
  6.             if '_' in text:
  7.                 if text[i] == '_':
  8.                     text = text[:i:] + text[i + 1::]
  9.             if '-' in text:
  10.                 if text[i] == '-':
  11.                     text = text[:i:] + text[i + 1].upper() + text[i + 2::]
  12.             i+=1
  13.         print(text)
  14.         return text
  15.     else:
  16.         return ''
  17.  
  18. def main():
  19.     text='the-stealth-warrior'
  20.     text.swapcase()
  21.     to_camel_case(text)
  22.  
  23. if __name__ == "__main__":
  24.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement