如何用C#中的双引号逗号双引号替换逗号? [英] How to replace comma with double quotes comma double quotes, in C#?

查看:130
本文介绍了如何用C#中的双引号逗号双引号替换逗号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



在Sql Server表中,我的日期用逗号分隔。



例如:2015-09-01,2015-09-03,2015-09-06,2015-09-10



我想用同样的字符串在我的javascript代码中,但是当把这个

字符串放在alert中时,我得到的是-ve值,但不是这个字符串。



所以,我想用c#中的,代替。



我尝试过:



 C#
公共对象SessionScheduleDates
{
get {return Session!= null? Session.ScheduleDates:string.Empty; }
}

Javascript
< script>
var ScheduleDates;
ScheduleDates =(<%= SessionScheduleDates%>);
alert(ScheduleDates);
< / script>

结果:
-34268

实际在寻找:
2015-09-01,2015-09-03,2015-09-06 ,2015-09-10





任何人都可以帮助我吗?





谢谢

解决方案

尝试:

  string  input =   2015-09-01,2015-09-03 ,2015-09-06,2015-09-10\" ; 
string output = input.Replace( \,\);

除此之外,你可能真的想这样做:

  string  input =   2015-09-01,2015-09-03,2015-09-06,2015-09-10; 
string output = \ + input.Replace( \,\)+ \;

为了平衡双引号:

2015-09 -01\" , 2015年9月3日, 2015年9月6日, 2015年9月10日


Hi Guys,

In Sql Server table, i have dates separated by commas.

Eg: "2015-09-01,2015-09-03,2015-09-06,2015-09-10"

I want to use this same string in my javascript code, but when put this
string in alert, i'm getting -ve values, but not this same string.

So, I want to replace , with "," in c#.

What I have tried:

C#
public object SessionScheduleDates
{
  get { return Session != null ? Session.ScheduleDates : string.Empty; }
}

Javascript
<script>
   var ScheduleDates;
    ScheduleDates = (<%= SessionScheduleDates %>);
    alert(ScheduleDates);
</script>

Result:
-34268

Actually looking for:
"2015-09-01,2015-09-03,2015-09-06,2015-09-10"



Can any one please help me?


Thanks

解决方案

Try:

string input = "2015-09-01,2015-09-03,2015-09-06,2015-09-10";
string output = input.Replace(",", "\",\"");

Except, you probably really want to do this:

string input = "2015-09-01,2015-09-03,2015-09-06,2015-09-10";
string output = "\"" + input.Replace(",", "\",\"") + "\"";

In order to balance up the double quotes:

"2015-09-01","2015-09-03","2015-09-06","2015-09-10"


这篇关于如何用C#中的双引号逗号双引号替换逗号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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