如何在扼杀中清除空间? 例如:
<>>Input:
/var/www/site/Brand new document.docx
<<>Output>:
/var/www/site/Brandnewdocument.docx
如何在扼杀中清除空间? 例如:
<>>Input:
/var/www/site/Brand new document.docx
<<>Output>:
/var/www/site/Brandnewdocument.docx
这?
str = str.replace(/s/g, );
例
var str = /var/www/site/Brand new document.docx ;
document.write( str.replace(/s/g, ) );
<>Update: http://stackoverflow.com/questions/5964373/is-there-a-difference-between-s-g-and-s-g> 这个问题:
str = str.replace(/s+/g, );
这是一个更好的解决办法。 它产生同样的结果,但它更快。
www.un.org/Depts/DGACM/index_spanish.htm Regex
s
is the regex for "whitespace", and g
is the "global" flag, meaning match ALL s
(whitespaces).
作为旁观,你可以把你想要的东西的单项引用内容替换为内容,这样你就可以用任何其他扼杀手段取代白色空间。
var a = b = " /var/www/site/Brand new document.docx ";
console.log( a.split( ).join( ) );
console.log( b.replace( /s/g, ) );
这样做的两种方式!
基准:
这里我的结果——(2018.07.13) MacOs High Sierra 10.13.3 on Zheng 67.0.3396 (64-bit), Safari 11.0.3 (13604.5.6), 590.0.2 (64-bit) :
简短说明类似于欧佩斯问题的例子
所有浏览器最快的解决办法是/g
(regexp1a)。 - Chrome17.7M(业务/安全),Sharma 10.1M,8.8M。 所有浏览器的速率最小的是split-join
解决方案。 更改<代码>至s
或添加+
或i
至 regexp放慢处理过程。
显示大约3个温和特性的结果是:
您可在以下机器上操作:。
您还利用了最新的联合材料之一:
/var/www/site/Brand new document.docx .replaceAll( , );
容易
someString.replace(/ /g, );
// or
someString.replace(/s/gm, );
var input = /var/www/site/Brand new document.docx ;
//remove space
input = input.replace(/s/g, );
//make string lower
input = input.toLowerCase();
alert(input);
https://jsfiddle.net/d4t8ozvj/>Click here for working example
<Without regexp,仅对一次情况进行罚款。
input = input.replace( , );
This is faster as simple ! Could help some of you in some cases.
var output = /var/www/site/Brand new document.docx .replace(/ /g, "");
or
var output = /var/www/site/Brand new document.docx .replace(/ /gi,"");
注:虽然你在拆除空间时使用g或gi,但两者都是一样的。
如果我们在替代职能中使用g,它将检查确切的配对。 但是,如果我们利用巨头,它忽略了案件的敏感性。
http://www.w3schools.com/jsref/jsref_replace.asp”rel=“nofollow” 。
你们可以利用规章将空间从扼杀中移走。
let str = /var/www/site/Brand new document.docx ;
let result = str.replace(/s/g, );
Regex + 替换()
尽管reg鱼可能较慢,但在许多情况下,开发商仅仅在考虑速度不相干时操纵了几条str。 即便是/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/或/
let string = /var/www/site/Brand new document.docx ;
let path = string.replace(/s/g, );
// path => /var/www/site/Brandnewdocument.docx
Split() + Join()
利用Split + Join允许对扼杀进行进一步的系统操纵。
let string = /var/www/site/Brand new document.docx ;
let path => string.split( ).map(char => /(s|.)/.test(char) ? / : char).join( );
// "/var/www/site/Brand/new/document/docx";
使用<条码> 取代所有条码>似乎最简单。 (我可以为最快者 t)
/var/www/site/Brand new document.docx .replaceAll( , )
见:。
替代所有(所有)方法回收了一种新的体形,其形形形形形形形形形形形形色色。 模式可以是体力或试射,替代可以是体力,也可以是要求每一方配对的功能。
Easiest way to remove spaces from the string is use replace in this way
let str = /var/www/site/Brand new document.docx ;
let result = str.replace(/s/g, );
var str = /var/www/site/Brand new document.docx ;
document.write( str.replace(/s/g, ) );
----------
How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.
I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...
Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...
Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...
I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...
Is it possible for someone to give me a few pointers on how to display a multidimensional array in the form of a bar graph? The array is multidimensional, with three elements in each part - and the ...
Is it possible to reload a form after file-input change? I have a form where the user can chose an image for upload. I also have a php script which displays that image resized. I only wonder if it ...
I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.