草庐IT

string-algorithm

全部标签

Javascript - string.replace() 文本跨越多行?

假设我有文本(不是html),我是从文本区域中提取的。看起来像:ALTERLOGIN[user1]DISABLEGO~~~~~~~~~~~~~importantstufftokeep~~~~~~~~~~~~~~~~~~~~~~~~~~~~importantstufftokeep~~~~~~~~~~~~~~~~~~~~~~~~~~~~importantstufftokeep~~~~~~~~~~~~~~~ALTERLOGIN[user2]DISABLEGO~~~~~~~~~~~~~importantstufftokeep~~~~~~~~~~~~~~~~~~~~~~~~~~~~importa

javascript - 未捕获的语法错误 : Unexpected string in my JavaScript

我在我的JavaScript中收到UncaughtSyntaxError:Unexpectedstring错误,老实说,我无法弄清楚代码有什么问题。我看过类似的问题,但找不到解决方案。错误出现在下面用星号突出显示的行中。$("#items1").change(function(){if($(this).data('options')===undefined){$(this).data('options',$('#items2option').clone());}varcheckval=$(this).val();/*thisline:*/varoptions=$(this).data(

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