Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
165
rated 0 times [  167] [ 2]  / answers: 1 / hits: 29582  / 14 Years ago, sun, august 15, 2010, 12:00:00

I have an array filled with strings, a value can for example be not updated for > days. I use the values in the array to create some url's and need to remove the /<> and other illegal URL characters. How do I easiest do this?



I started with



var Name0 = title[0].substring(1).replace( , %20).replace(/, ) + '.aspx';
var Name1 = title[1].substring(1).replace( , %20).replace(/, ) + '.aspx';
and so on but can I do this in a better way?


Thanks in advance.


More From » jquery

 Answers
9

If you wish to keep the symbols in the URI, but encode them:



encodedURI = encodeURIComponent(crappyURI);


If you wish to build 'friendly' URIs such as those on blogs:



niceURI = crappyURI.replace(/[^a-zA-Z0-9-_]/g, '');

[#95916] Thursday, August 12, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
albert

Total Points: 652
Total Questions: 105
Total Answers: 108

Location: Pitcairn Islands
Member since Fri, Oct 15, 2021
3 Years ago
;