草庐IT

STRING_PART

全部标签

javascript - String.prototype.replace() 删除破折号和下划线

我正在尝试使用String.prototype.replace()删除字符串中出现的所有破折号和下划线,但它不起作用,我也不知道为什么。我的代码:varstr="dash-and_underscore";str=str.replace(/_|\-/,"");console.log(str);输出:"dashand_underscore"在Chrome控制台中。由于|的行为类似于OR运算符,我做错了什么?我试过解决方案here,但它没有用,或者我太笨了,无法理解-这是一个选项;) 最佳答案 试试这个:str=str.replace(/

javascript - 如何剥离数据 :image part from a base64 string of any image type in Javascript

我目前正在执行以下操作以在Javascript中解码base64图像:varstrImage="";strImage=strToReplace.replace("data:image/jpeg;base64,","");strImage=strToReplace.replace("data:image/png;base64,","");strImage=strToReplace.replace("data:image/gif;base64,","");strImage=strToReplace.replace("data:image/bmp;base64,","");正如您在上面看到的

javascript - `String.raw` 当最后一个字符是 `\`

String.raw非常有用。例如:letpath=String.raw`C:\path\to\file.html`但是,当模板字符串的最后一个字符是\时,就会变成语法错误。letpath=String.raw`C:\path\to\directory\`UncaughtSyntaxError:Unterminatedtemplateliteral我暂时采用这种方式。letpath=String.raw`C:\path\to\directory\`.trimRight()我可以使用String.raw编写最后一个字符为\的模板字符串吗? 最佳答案

c# - 如何在 javascript 中编写等效于 Convert.ToBase64String() 的 javascript?

这个问题在这里已经有了答案:HowcanyouencodeastringtoBase64inJavaScript?(33个答案)关闭9年前。我有字节数组,我可以在C#中使用Convert.ToBase64String()方法转换它。我在javascript中编写了与此方法等效的代码,如下所示。但结果不同。在C#中:byte[]data=...Convert.ToBase64String(data)在js中functionGetStringFromByteArray(array){varresult="";for(vari=0;i如何在js中成功?

JavaScript 符号类型 : (non-string object keys)

什么是“Symbol”javascript类型asmentionedinthisECMAScript6draftspecification?引用规范:TheSymboltypeisthesetofallnon-StringvaluesthatmaybeusedasthekeyofanObjectproperty.EachpossibleSymbolvaluesisuniqueandimmutable.Symbolvalueshaveasingleobservableattributecalled[[Private]]whoseimmutablevalueiseithertrueorfa

javascript - "Error: path must be a string"(v5.10.0)

我有这个文件(一大堆JS文件),它曾经与browserify(5.10.0)一起工作)直到几天前,现在没有了。这是我正在运行的:$browserifyindex.js-odist/out.bundle.js输出是:Error:pathmustbeastringat/usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:15:16atprocess._tickCallback(node.js:419:13)谁知道这可能是什么原因造成的?有没有一种方法可以调试它来尝试找出困扰browserify的是什

Javascript 权威指南 : the confusion of steps of converting object to a string

根据Javascript权威指南第6版3.8.3节:Toconvertanobjecttoastring,JavaScripttakesthesesteps:•IftheobjecthasatoString()method,JavaScriptcallsit.Ifitreturnsaprimitivevalue,JavaScriptconvertsthatvaluetoastring(ifitisnotalreadyastring)andreturnstheresultofthatconversion.Notethatprimitive-to-stringconversionsarea

javascript - 为什么不推荐使用 String.prototype.substr()?

ECMAScript标准中提到了它here那:...ThesefeaturesarenotconsideredpartofthecoreECMAScriptlanguage.ProgrammersshouldnotuseorassumetheexistenceofthesefeaturesandbehaviourswhenwritingnewECMAScriptcode.ECMAScriptimplementationsarediscouragedfromimplementingthesefeaturesunlesstheimplementationispartofawebbrowse

javascript - 这个新语法 gql`string` 是什么

这个问题在这里已经有了答案:Backticks(`…`)callingafunctioninJavaScript(3个答案)关闭2年前。constGET_DOGS=gql`{dogs{idbreed}}`;我从here中找到了这个新语法.你能解释一下这个语法吗?我在哪里可以找到有关它的详细信息?

javascript - 创建小书签 : Append current URL with specific string

我正在尝试创建一个小书签,它将更改我当前所在页面的URL,并加载一个更改了URL字符串的新页面。我已经查看了许多关于小书签的其他主题,但我还没有找到适合我的解决方案。我希望能够更改如下所示的URL:http://mywebsite.com/directory/page.html?referral=Google&visit=1到:http://mywebsite.com/directory/page.html?dog=Fido&cat=Mittens三个目标:1)在?之后删除现有URL中的任何内容标记。2)在问号后附加“dog=Charlie&cat=Mittens”。3)立即使用新UR