File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ package easy ;
2+
3+ /**
4+ * Have the function SnakeCase(str) take the str parameter being passed
5+ * and return it in proper snake case format where each word is lowercased
6+ * and separated from adjacent words via an underscore.
7+ * The string will only contain letters and some combination
8+ * of delimiter punctuation characters separating each word.
9+ */
10+ public class SnakeCase {
11+
12+ /**
13+ * Snake Case function.
14+ *
15+ * @param str input string
16+ * @return a string in a snake case format
17+ */
18+ private static String snakeCase (String str ) {
19+ return str
20+ .toLowerCase ()
21+ .replaceAll ("([^a-z])" , " " )
22+ .replaceAll (" +" , "_" )
23+ .trim ();
24+ }
25+
26+ /**
27+ * Entry point.
28+ *
29+ * @param args command line arguments
30+ */
31+ public static void main (String [] args ) {
32+ var result1 = snakeCase ("Revolt is the right of the people" );
33+ System .out .println (result1 );
34+ var result2 = snakeCase ("Fortitude is the guard and support of the other virtues" );
35+ System .out .println (result2 );
36+ }
37+
38+ }
You can’t perform that action at this time.
0 commit comments