惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

N
Netflix TechBlog - Medium
月光博客
月光博客
Y
Y Combinator Blog
WordPress大学
WordPress大学
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
雷峰网
雷峰网
美团技术团队
T
Tailwind CSS Blog
小众软件
小众软件
量子位
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
有赞技术团队
有赞技术团队
P
Proofpoint News Feed
G
Google Developers Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Recent Announcements
Recent Announcements
The GitHub Blog
The GitHub Blog
博客园 - 三生石上(FineUI控件)
云风的 BLOG
云风的 BLOG
Vercel News
Vercel News
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
爱范儿
爱范儿
V
Visual Studio Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More

博客园 - 秋天

sqlserver触发器 ASP.NET Core 性能对比评测(ASP.NET,Python,Java,NodeJS) URL地址中使用中文作为的参数【转】 百度地图API操作 [ASP.Net ]利用ashx搭建简易接口 使用RMS API 自定义Office(Word、Excel、PPT)加密策略 C#Excel文件加密实现,支持xlsx、docx、pptx(C#\Net\Asp.Net) - 秋天 - 博客园 使用vs2015搭建Asp.net Core 千万级规模高性能、高并发的网络架构经验分享 ASP.NET MVC学习系列(二)-WebAPI请求 浅谈HTTP中Get与Post的区别 ASP.NET MVC学习系列(一)-WebAPI初探 .net下web页生产一维条形码 微软源代码管理工具TFS2013安装与使用详细图文教程(Vs2013) Nginx搭建反向代理服务器过程详解 windows下安装nginx 我的架构设计~用层关系图说说mvc,mvvm,soa,ddd Ajax中Get请求与Post请求的区别 将String转化成Stream,将Stream转换成String
js中对String去空格
秋天 · 2019-11-26 · via 博客园 - 秋天
学习了,记录下~

str为要去除空格的字符串:
去除所有空格:   
str   =   str.replace(/\s+/g,"");       
去除两头空格:   
str   =   str.replace(/^\s+|\s+$/g,"");
去除左空格:
str=str.replace( /^\s*/, '');
去除右空格:
str=str.replace(/(\s*$)/g, "");

SCRIPT LANGUAGE="JavaScript">    
<!--    
//出处:网上搜集    
// Trim() , Ltrim() , RTrim()    
String.prototype.Trim = function()    
{    
returnthis.replace(/(^\s*)|(\s*$)/g, "");    
}    
String.prototype.LTrim = function()    
{    
returnthis.replace(/(^\s*)/g, "");    
}    
String.prototype.RTrim = function()    
{    
returnthis.replace(/(\s*$)/g, "");    
}    
//-->    
</SCRIPT>    
<input type="text" value="    前后都是空格     " id="space">    
<input type="button" value="去前后空格" onclick="javascript:document.getElementById('space').value=document.getElementById('space').value.Trim();document.getElementById('space').select();">    
<input type="button" value="去前空格" onclick="javascript:document.getElementById('space').value=document.getElementById('space').value.LTrim();document.getElementById('space').select();">    
<input type="button" value="去后空格" onclick="javascript:document.getElementById('space').value=document.getElementById('space').value.RTrim();document.getElementById('space').select();">    
<input type="button" value="还原" onclick="javascript:document.getElementById('space').value='      前后都是空格     ';">    
<a href="http://www.yaoasnsi.com" target="_blank">访问yaosansi.com</a> 

去除所有空格: 
str = str.replace(/\s+/g,"");
去除两头空格: 
str = str.replace(/^\s+|\s+$/g,"");
去除空格(TimeSheet用过)
arg0=arg0.replace(/\s+$|^\s+/g,"");

来源:http://www.cnblogs.com/fumj/p/3406420.html