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?
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?
Share asked Oct 15, 2013 at 21:26 dimmechdimmech 8779 silver badges19 bronze badges 2-
2
folderArray.push(sFolder.name.replace('%20',' '))
? – PlantTheIdea Commented Oct 15, 2013 at 21:28 - 1 There is a replace function which should work developer.mozilla/en-US/docs/Web/JavaScript/Reference/… – Schleis Commented Oct 15, 2013 at 21:28
3 Answers
Reset to default 4use decodeURI()
decodeURI('Folder%20one, Folder%20two, Folder%20three');
// -> "Folder one, Folder two, Folder three"
%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
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', ''));
}