草庐IT

string-parsing

全部标签

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 - JSON.parse(fs.readFileSync()) 返回缓冲区 - 数字字符串

我正在使用一个简单的Node.js从有效的jsonfile中提取信息(使用JSLint检查),但是我使用的代码没有返回预期值:squadJSON=JSON.parse(fs.readFileSync('./squads/squad'+whichSquad+'.json'));它返回:{type:'Buffer',data:[123,10,32,32,34,97,99,...548moreitems]}为什么会发生这种情况? 最佳答案 fs.readFileSync()如果您未指定编码,则返回一个Buffer。https://node

javascript - JSON.parse() 导致错误 : `SyntaxError: Unexpected token in JSON at position 0`

我正在用Node.js编写我的第一个应用程序。我正在尝试从数据以JSON格式存储的文件中读取一些数据。我收到这个错误:SyntaxError:UnexpectedtokeninJSONatposition0atObject.parse(native)这是这部分代码://readsavedaddressesofallusersfromaJSONfilefs.readFile('addresses.json',function(err,data){if(data){console.log("ReadJSONfile:"+data);storage=JSON.parse(data);这是c

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 - 在 JavaScript 中替换 Parse.Collections 的最佳方法是什么

Parse.com已经从JSSKD中删除了Backbone样式Parse.Collection(从这里https://parse.com/docs/downloads):SDKnolongercontainsBackbone-specificbehavior.Movingforward,thecoreSDKwillnotbetiedtoanysingleframework,butwewillworkwiththecommunitytoproduceup-to-datebindingslikeParse+React.ThemajorchangesaretheremovalofParse.

javascript - JSON.parse() 在 pentaho 的 javascript 中不起作用

我正在尝试使用修改后的Java脚本值步骤从字符串形成数组。这是我解析字符串并形成JSON对象的代码。varinfo={};varkeywords='Adjustcourse(C-6),Identifyunderlyingfactors(C-4),Isolateteacheractions(C-3_)';if(keywords!=null&&keywords!=''){keywords=keywords.replace(/,/g,'","');keywords='["'+keywords+'"]';info.keywords=JSON.parse(keywords);}在JSON.par

javascript - 使用 AngularJS html5Mode (back4app/Parse-Server) 时如何解析 ExpressJS 路由

我正在使用使用Parse-Server的back4appBaaS服务。对于客户端,我使用html5Mode(true);运行AngularJS;我的问题是这不起作用:http://app.rizop.tv/dashboard虽然这是正确的:http://app.rizop.tv知道如何修复expressJS以正确的方式处理我的路由吗?我有这个配置:云\app.js//Helpermodulesthatwillbeusedvarpath=require('path');varbodyParser=require('body-parser')//ThisimportstheRouterth

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编写最后一个字符为\的模板字符串吗? 最佳答案

javascript - 更新 parse.com 表时出现“POST 400 错误请求”错误

尝试使用JSSDK更新parse.com上的表时,我收到“POST400错误请求”错误。varGallery=Parse.Object.extend("Gallery");vargallery=newGallery();varactiveArtworks=0;gallery.save(null,{success:function(gallery){gallery.set("activeArtworks",activeArtworks);gallery.save();}});请帮忙!我看不出这与parsehere提供的示例代码有何不同 最佳答案

javascript - 扩展 JavaScript 的 Date.parse 以允许 DD/MM/YYYY(非美国格式的日期)?

我想出了这个解决方案来扩展JavaScript的Date.parse函数以允许日期格式为DD/MM/YYYY(而不是美国标准[和默认]MM/DD/年年年):(function(){varfDateParse=Date.parse;Date.parse=function(sDateString){vara_sLanguage=['en','en-us'],a_sMatches=null,sCurrentLanguage,dReturn=null,i;//####Traversethea_sLanguages(asreportedbythebrowser)for(i=0;i在我的实际(do