Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
C#
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.
Posted
Comments
Andy Lanng 3-Jun-15 5:21am    
Personally I would check the source and correct the issue there. Is sounds like the first issue it that the values are being inserted into dr incorrectly.

To fix it, I would just use .replace:

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

I won't post as a solution as I'm sure another expert will have another idea
CHill60 3-Jun-15 5:40am    
Looked good to me!
Andy Lanng 3-Jun-15 5:42am    
I wasn't sure. Good to get confirmation though ^_^

1 solution

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:
C#
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900