How we can delete some special character from a string 开发者_Python百科by javascript
The best way is to replace it, either using a string or regular expression.
String:
// JavaScript Document
var string = 'Hello world!';
alert( string.replace( 'world', '' ) ); // Alerts "Hello !"
Regular Expression:
// JavaScript Document
var string = 'Hello world!';
alert( string.replace( /o/, '' ) ); // Alerts "Hell wrld!"
Well,
if the string to get cleaned up is mystring;
mysring = mystring.replace(/[^a-zA-Z 0-9]+/g,'');
will remove all charectes other than alpahnumeric from your string. You can modify the regular expression accordingly if you wan tot exclude some special characters from cleaning up.
精彩评论