字符串格式转义序列。 [英] string format escape sequence.

查看:117
本文介绍了字符串格式转义序列。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨guyes我有webmethod我从中获取一条记录并显示在我的asp:lable。



我有列表< string>在我的webmethod和阅读数据时我将其转换为字符串格式

 (dr.Read( ))
{
rst.Add( string .Format( {0},dr [ Practice_short_name ]));
}





但是当我在我的标签中显示数据时,我的格式就像。



[CEC2]



但我想要像



CEC2



如何从我的输出中取消括号[]和。



谢谢。

解决方案

这取决于你的数据来源:好像不想要的角色来了从那里。如果它们是,那么最好的方法是在源头删除它们,但如果你不能这样做那么子字符串:

  string   base  = dr [  Practice_short_name]的ToString(); 
rst.Add( base .Substring( 2 base .Length - 4 ));

如果每个值相同,或者如果不相同则为正则表达式。


hi guyes i have webmethod from which i am fetching one record and display in my asp:lable.

i have list<string> in my webmethod and while reading data i am converting it to string format

while(dr.Read())
  {
      rst.Add(string.Format("{0}",dr["Practice_short_name"]));
  }



but when i am displaying data in my lable i am getting format like.

["CEC2"]

but i want to be it like

CEC2

how to excape brackets [] and "" from my output.

Thanks.

解决方案

It depends on your data source: it looks like the unwanted characters are coming from there. If they are, then the best way is to remove them at source, but if you can't do that then either a substring:

string base = dr["Practice_short_name"].ToString();
rst.Add(base.Substring(2, base.Length - 4));

if every single value is the same, or a Regex if not.


这篇关于字符串格式转义序列。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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