-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringWork.java
More file actions
116 lines (88 loc) · 3.08 KB
/
Copy pathStringWork.java
File metadata and controls
116 lines (88 loc) · 3.08 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import java.util.StringTokenizer;
public class StringWork
{
public static void main(String[] args)
{
/*Character c = new Character('h');
System.out.println(c);*/
/*char c = 'H';
if (Character.isDigit(c))
System.out.println("This is a digit.");
if (Character.isLetter(c))
System.out.println("This is a letter.");
if (Character.isWhitespace(c))
System.out.println("This is a white space.");*/
/*String str = "3x8";
char first = str.charAt(0);
if (!Character.isDigit(first))
System.out.println("Error!!!");
if (str.charAt(1) != 'x')
System.out.println("Error!!"); */
/*String name = "Paul Wilkins";
if (name.startsWith("Paul"))
System.out.println(name + "starts with Paul"); */
/*
String[] classList = {"Banana", "Chris", "Patty", "Peter","Rubert",
"Erica", "Paul", "Steve"};
for (int i = 0; i < classList.length; i++)
{
if (classList[i].startsWith("Pa"))
System.out.println(classList[i]);
if (classList[i].regionMatches(3, "Rodert", 3, 1))
System.out.println(classList[i]);
System.out.println(classList[i] + " " + classList[i].indexOf("na"));// indexOf returns -1 if not found or index
}*/
/*int index = classList[0].indexOf("na");
System.out.println(index);
while (index != -1)
{
index = classList[0].indexOf("na", index + 1);
System.out.println(index);
}*/
/*
// using substring()
String name = "Paul Wilkins";
int space = name.indexOf(" ");
System.out.println(name.substring(space + 1));*/
/*String team = " Paul,Bob,Endwr,Marin,Joe ";
StringTokenizer st = new StringTokenizer(team.trim(), ",");
while (st.hasMoreTokens())
{
String token = st.nextToken();
System.out.println(token);
}
String[] tokens = (team.trim()).split(",");
for (int i = 0; i < tokens.length; i++)
{
System.out.println(tokens[i]);
}*/
/*
String phone = ("(415)555-5555, 541-1234-5678");
StringTokenizer st = new StringTokenizer(phone.trim(), "-");
String[] tokens = (phone.trim()).split("[-, ()]");
for (int i = 0; i < tokens.length; i++)
{
System.out.println(tokens[i]);
}*/
/*StringBuilder builder = new StringBuilder("New");
builder.append(" City");
builder.insert(4, "York ");// York in between
builder.replace(4, 13, "Mexico");// York City to Mexico
String city = "New City";
city = city.substring(0, 3) + " York" + city.substring(3);
System.out.println(builder);//System.out.println(city);*/
/* More info at Page 537 */
StringBuilder str = new StringBuilder("I'm really really really excited!");
System.out.println("Old String: " + str);
String find = "really";
String replace = "very";
//String strReplace = str.replace(find, replace);
int index = str.indexOf(find);// get the index of the string to be found
while (index != -1)// index will be -1 if the specified string not found
{
str.replace(index, index + find.length(), replace);
index = str.indexOf(find);// get the index and whie loop keep searching from the current index.
}
System.out.println("New Replaced: " +str);
}// end main
}