需要在 javascript 中对 ajax 查询进行正确的修剪吗? [英] Need to do a right trim on ajax query in javascript?

查看:34
本文介绍了需要在 javascript 中对 ajax 查询进行正确的修剪吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 JavaScript 中,我想对字符串末尾的所有特殊字符进行正确的修剪.我的一段代码只对连字符 (-) 进行修剪..还需要所有特殊字符 (:.,()+-=/[]\@#$%^&*).

In JavaScript, I wanted to do the right trim for all the special characters at the end of the string. My Piece of code doing the trim for hyphen (-) only..Need for all the special characters(:.,()+-=/[]\@#$%^&*) as well.

var s = "DB-";
var x = s.replace(/-+$/,'');
console.log(x);

对此有什么帮助吗?

推荐答案

这应该可以解决问题.

var x = "abcde#$@asbd#$^@$";
x.slice(0,x.search(/\W*$/));

这只会修剪掉字符串末尾的特殊字符.它将在字符串的主体中留下特殊字符.

This will only trim off the special characters at the end of the string. It will leave special characters that are in the body of the string.

这篇关于需要在 javascript 中对 ajax 查询进行正确的修剪吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆