-
Notifications
You must be signed in to change notification settings - Fork 0
/
clsStrings.py
59 lines (44 loc) · 2.01 KB
/
clsStrings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import string, sys
class string_format:
def __init__(self):
pass
def title(self, text):
returnText = ''
for x in range(len(text)):
if x == 0:
returnText = str(text[x]).upper()
elif str(text[x - 1]) == ' ':
returnText += str(text[x]).upper()
else:
returnText += str(text[x])
return returnText
def sentence(self, text):
returnText = ''
for x in range(len(text)):
if x == 0:
returnText = str(text[x]).upper()
elif x > 3 and (str(text[x - 2:x]) == '. ' or str(text[x - 3:x]) == '. '):
returnText += str(text[x]).upper()
else:
returnText += str(text[x])
return returnText
def camelCase(self, text):
returnText = ''
for x in range(len(text)):
if x == 0:
returnText = str(text[x]).upper()
elif str(text[x - 1]) == ' ':
returnText += str(text[x]).upper()
elif str(text[x]).isalnum():
returnText += str(text[x])
return returnText
def snake(self, text):
returnText = text.replace(' ', '_').replace("'", '_').replace('.', '').replace(',', '').lower()
return returnText
if __name__ == "__main__":
myFormat = string_format()
print(myFormat.title("they're over at bill's house. and, BTW, we are not going. okay?"))
print(myFormat.sentence("they're over at bill's house. and, BTW, we are not going. okay?"))
print(myFormat.camelCase("they're over at bill's house. and, BTW, we are not going. okay?"))
print(myFormat.snake("they're over at bill's house. and, BTW, we are not going. okay?"))
print(myFormat.sentence("This group is dedicated to Python Developers & Programmers which discusses all aspects of the server. python is great."))