-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathURLify.java
More file actions
40 lines (29 loc) · 786 Bytes
/
URLify.java
File metadata and controls
40 lines (29 loc) · 786 Bytes
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
package basic;
public class URLify {
//Remove space by %20
/*
* Write a method to replace all spaces in a string with '%20'.
* You may assume that the string has sufficient space at the end to hold the additional characters,
* and that you are given the "true" length of the string.EXAMPLE
Input: "Mr John Smith ", 13
Output: "Mr%20John%20Smith"
*/
//remove trailing and begining space
String url;
void setUrl(String url){
this.url=url;
}
String getURL(){
return this.url;
}
URLify(String url){
url=url.trim();
url=url.replaceAll(" ", "%20");
System.out.println(url);
}
public static void main(String args[]){
URLify u=new URLify("Mr John Smith ");
//u.setUrl("");
// System.out.println(u.getURL());
}
}