Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 22d7ded

Browse files
Update Tutorial.md
1 parent a38c8c6 commit 22d7ded

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

‎ArraysAndStrings/Tutorial.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,19 @@ public void shuffleArray(int arr[]) {
129129
**Shuffle a Deck of cards**
130130

131131
[Java Program](https://github.com/ankurjuneja/React-Java-Concepts/blob/master/src/ArraysAndStrings/Deck.java)
132+
133+
**Method to replace all spaces in a string with %20**
134+
```
135+
public static String replaceSpaceWithPercent20(String str) {
136+
char[] charArray = str.toCharArray();
137+
StringBuilder sb = new StringBuilder();
138+
String percent20 = "%20";
139+
for(int i = 0; i < charArray.length-1; i++) {
140+
if(charArray[i] == ' ' && charArray[i+1] != ' ')
141+
sb.append(percent20);
142+
else
143+
sb.append(charArray[i]);
144+
}
145+
return sb.toString();
146+
}
147+
```

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /