0

When using the folder.name or file.name Javascript classes, the returned values include the %20 characters in place of spaces in actual file or folder names.

For Example:

if (sFolder instanceof Folder) {
   folderArray.push(sFolder.name);
}

Returns:

Folder%20one, Folder%20two, Folder%20three

What I need is:

Folder one, Folder two, Folder three

The same thing is happening with files, if there are any spaces in the file name they are replaced with %20. How can I remove those characters if folder names have 1 or even multiple spaces?

2

3 Answers 3

4

use decodeURI()

decodeURI('Folder%20one, Folder%20two, Folder%20three');
// -> "Folder one, Folder two, Folder three"
Sign up to request clarification or add additional context in comments.

Comments

3

%20 is the HTML encoded value for a space. URLs don't handle spaces, so they HTML/URL encode this value.

What you're looking for is decodeURIComponent.

You can see an example here

Comments

0

I found that the basic replace method only removed the first instance of the characters to be replaced. DecodeURI was a better answer however, I also found that you could use the following expression within the replace method and that you could use the method in succession for different character sets which was not in the documentation I read for that Method.

if (sFolder instanceof Folder) {
   folderArray.push(sFolder.name.replace (/%20/g,' ').replace ('.html', ''));
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.