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?

dimmech
  • 827
  • 9
  • 19
  • 2
    `folderArray.push(sFolder.name.replace('%20',' '))`? – PlantTheIdea Oct 15 '13 at 21:28
  • 1
    There is a replace function which should work https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace?redirectlocale=en-US&redirectslug=JavaScript%2FReference%2FGlobal_Objects%2FString%2Freplace – Schleis Oct 15 '13 at 21:28

3 Answers3

4

use decodeURI()

decodeURI('Folder%20one, Folder%20two, Folder%20three');
// -> "Folder one, Folder two, Folder three"
nicksweet
  • 3,929
  • 1
  • 20
  • 22
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

Community
  • 1
  • 1
Codeman
  • 12,157
  • 10
  • 53
  • 91
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', ''));
}
dimmech
  • 827
  • 9
  • 19