-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStringParser.java
40 lines (36 loc) · 1.04 KB
/
StringParser.java
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
public class StringParser
{
private StringParser()
{}
public static String formatString(String input)
{
input = input.toLowerCase();
input = input.replaceAll(" the ", " ");
input = input.replaceAll(" a ", " ");
input = input.replaceAll(" an ", " ");
input = input.replaceAll(" this ", " ");
input = input.replaceAll(" that ", " ");
input = input.replaceAll(" to ", " ");
input = input.trim();
while (input.indexOf(" ") >= 0)
input = input.replaceAll(" ", " ");
return input;
}
public static String getCommand(String input)
{
if(input.indexOf(" ") > 0)
return input.substring(0,input.indexOf(" "));
else
return input;
}
public static String getPhrase(String input)
{
if(input.indexOf(" ") > 0)
{
input = input.substring(input.indexOf(" ") + 1);
return input;
}
else
return "";
}
}