Update and rename removeAllWhitespaces.md to removeWhitespace.md

This commit is contained in:
Angelos Chalaris
2020-10-13 09:37:17 +03:00
committed by GitHub
parent 2d919d88c6
commit 800dd2b4ae
2 changed files with 16 additions and 22 deletions

View File

@ -1,22 +0,0 @@
---
title: removeAllWhitespaces
tags: string,regexp,beginner
---
Returns a string removing any and all whitespaces.
- Use `String.prototype.replace()` with a regular expression to replace any and all occurrences of whitespace characters with a empty string.
```javascript
const removeAllWhitespaces = (string) => {
if(!string || typeof string !== "string") return "";
return string.replace(/\s+/g, ""); // trimming the whitespace, if any
}
```
```javascript
removeAllWhitespaces(" Hello, I've a lot of white spaces. \n Including a line break."); // "Hello,I'vealotofwhitespaces.Includingalinebreak."
```

View File

@ -0,0 +1,16 @@
---
title: removeWhitespace
tags: string,regexp,beginner
---
Returns a string with whitespaces removed.
- Use `String.prototype.replace()` with a regular expression to replace all occurrences of whitespace characters with an empty string.
```js
const removeWhitespace = str => str.replace(/\s+/g,'');
```
```js
removeWhitespace('Lorem ipsum.\n Dolor sit amet. '); // 'Loremipsum.Dolorsitamet.'
```