admin管理员组文章数量:1410689
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', ''));
}
本文标签: How do I replace the 20 characters in a path variable JavascriptStack Overflow
版权声明:本文标题:How do I replace the %20 characters in a path variable? Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744814413a2626609.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论