1

How to decode spacial character in xamairn forms

Inside my label text = "Sample & Text" instead of showing original text, its showing "Sample & Text"

so how to solve this?

Himanshu Dwivedi
  • 7,934
  • 3
  • 31
  • 52
Vidhya
  • 443
  • 8
  • 27

2 Answers2

2

& is used for displaying & in XAML. If you want to display Sample & Text on code behind, there's no need to encode it to Sample & Text. You could set the value directly. i.e. here is a list view's items source:

var list = new List<string>();
for (int i=0; i<10; i++)
{
    var str = "Sample & Text";
    list.Add(str);
}
listView.ItemsSource = list;

It shows correctly:

enter image description here

However, if your original text from the server is Sample &amp; Text and you want to display the decoded format, you can try System.Net.WebUtility.HtmlDecode():

var str = System.Net.WebUtility.HtmlDecode("Sample &amp; Text");
Ax1le
  • 6,563
  • 2
  • 14
  • 61
1

Try this:

<Label Text="Sample &amp;Text"/>

This will display "Sample & Text"

Himanshu Dwivedi
  • 7,934
  • 3
  • 31
  • 52