社区
JavaScript
帖子详情
有什么方法可以去掉字符串左右两边的空格?????
rywln
2002-07-05 04:42:10
请指教?
...全文
95
5
打赏
收藏
有什么方法可以去掉字符串左右两边的空格?????
请指教?
复制链接
扫一扫
分享
举报
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
zhiwen_huang
2002-07-05
打赏
举报
回复
自己写一个
function LTrim(tempString){
while (tempString.charAt(0) == ' ') {
tempString= tempString.substring(1,tempString.length);
}
return tempString;
}
function RTrim(tempString){
while (tempString.charAt(tempString.length - 1) == ' ') {
tempString= tempString.substring(0,tempString.length - 1);
}
return tempString;
}
zhiwen_huang
2002-07-05
打赏
举报
回复
http://www.csdn.net/expert/topic/806/806410.xml?temp=.3242456
zhiwen_huang
2002-07-05
打赏
举报
回复
自己来定义Trim LRrim RTrim
<script language=javascript>
String.prototype.Trim = function(){return this.replace(/(^\s*)|(\s*$)/g, "");}
String.prototype.LTrim = function(){return this.replace(/(^\s*)/g, "");}
String.prototype.RTrim = function(){return this.replace(/(\s*$)/g, "");}
var s = " leading and trailing spaces ";
window.alert(s + " (" + s.length + ")");
s = s.Trim();
window.alert(s + " (" + s.length + ")");
</script>
flyxing
2002-07-05
打赏
举报
回复
function trim(value){
var res = String(value).replace(/^[\s]+|[\s]+$/g,'');
return res;
}
X25
2002-07-05
打赏
举报
回复
str=str.replace(/(^\s*)|(\s*$)/g, "");
JS
去掉
字符串
两边
(
左右
)的
空格
(js去
空格
)
我们在使用JS脚的时候,常常需要把
字符串
两边
的
空格
进行清除,它有像ASP或者ASP.NET内至的函数吗?答案是没有的,这个需要自己写代码实现。您不会写?没关系,下面告诉您怎么实现,实现的
方法
有两种,一种是使用substring函数实现,另一种就是利用正则表达式实现。哪个好?差不多,根据自己的爱好吧! 以下是引用片段: //substring的方式 //
去掉
左右
空格
fu
字符串
如何
去掉
左右
空格
在比较excel表中两个
字符串
是否相等的时候,没有注意到前后
空格
,导致匹配的时候不相等,那么怎么
去掉
一个
字符串
的多余
空格
呢? 第一个
方法
:java中已有
去掉
字符串
前后
空格
的
方法
trm() 测试代码如下: public static void main(String args[]) { String string = " hhdh d";//该
字符串
前面有两个
空格
...
去掉
字符串
左右
两边
多余的
空格
传入
字符串
string类型,
去掉
右边多的
空格
/*********************************************************************** ** 功能:
去掉
字符串
右边的
fortran
去掉
字符
两边
的
空格
len
字符串
的长度 trim
去掉
字符串
右边的
空格
len_trim 不算
字符串
右边的
空格
的
字符串
的长度 lnblnk
字符串
最后一个非
空格
的字符的位置 index/scan 寻找指定字符的在
字符串
出现的位置 verify 第一个非指定字符在
字符串
出现的位置 adjustl 移动
字符串
左对齐,
去掉
打头的
空格
adjustr 移动
字符串
...
c++
字符串
去掉
首尾
空格
_C++
去掉
字符串
的首尾
空格
和全部
空格
#include #include using namespace std;//
去掉
收尾
空格
string& ClearHeadTailSpace(string &str){if (str.empty()){return str;}str.erase(0,str.find_first_not_of(" "));str.erase(str.find_last_not_of(" ") +...
JavaScript
87,984
社区成员
224,681
社区内容
发帖
与我相关
我的任务
JavaScript
Web 开发 JavaScript
复制链接
扫一扫
分享
社区描述
Web 开发 JavaScript
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章