从字符串中删除双引号 [英] Remove double quotes froma string

查看:139
本文介绍了从字符串中删除双引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:



有两个输入文本,我需要从输入文本中获取用户输入的值。结合它们并从中获取java脚本日期





代码

Scenario:

Have two input texts, i need the get the user entered values out of the input texts. Combine them and get the java script date out of it


Code

var UserStartTime = Control1.value;//string hh,mm,ss
var UserStartDate = Control2.value//string yyyy,mm,dd

var DateString = UserStartDate +","+ UserStartTime;//string ex:2013,11,14,03,00,00
var newTime = (new Date(DateString));//this fails and returns invalid date







I ssue:



由于双引号,代码返回无效日期。 DateString =2013,11,14,03,00,00的值。如何从此字符串中删除双引号并将该值转换为JS日期?



到目前为止我尝试了什么并且没有工作:




Issue:

The code returns invalid date because of double quotes. Value of DateString = "2013,11,14,03,00,00". How do i remove the double quotes from this string and convert that value to JS date?

What i have tried so far and didn't work:

var NonQuotesVaraible = new String(DateString);
var temp = Number(NonQuotesVaraible );

DateString.replace(/"/g, ""); 

DateString.replace(/["]/g, "");

DateString.replace(/\"/g, "");

JSON.parse(DateString);

DateString.replaceAll("^\"|\"$", "");

DateString.replace("\"","");

DateString.valueOf();

In all the cases double quotes are still present.

推荐答案

);

DateString.replace( \ );

DateString.valueOf();

在所有情况下, double 引号仍然存在。
", ""); DateString.replace("\"",""); DateString.valueOf(); In all the cases double quotes are still present.


当你使用

When you are using
DateString.replace("\"","");



也许你应该正在使用......


perhaps you should be using...

DateString = DateString.replace("\"","");



这将产生很大的不同,因为string.Replace()返回修改后的字符串,它不会修改你调用它的字符串。


This will make a big difference because string.Replace() returns the modified string, it doesn't modify the string you call it on.


这将起作用删除所有出现的

This will work to remove all occurrences of ":
DateString = DateString.replace(/"/g, '');





我看起来你已经有了类似的变种。有什么不好的是你试图使用试错法,而你却可以阅读一些帮助文档,只想几秒钟: http://www.w3schools.com/jsref/jsref_replace.asp [ ^ ]。



现在,请看我对这个问题的评论。我不明白为什么这些不需要的字符应该首先出现在你的字符串中。



-SA

这篇关于从字符串中删除双引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆