Вопрос

I want to add ascii char in my listview. Here is my code:

ListViewItem item = new ListViewItem();
item.Text = Convert.ToString(count);
item.SubItems.Add(imgList.imgName.Substring(0, imgList.imgName.Length - 3));
item.SubItems.Add(Convert.ToString(imgList.score));
if (Util.FNameExtraction(addImage.FileName).Substring(0, 5) == imgList.imgName.Substring(0, 5))
{
    // ASCII should place
}

LvResultList.Items.Add(item);

I tried several types but could not find any solution.

Here is what i tried:

item.Text = Convert.ToString(char(195)) ;
item.Text = 195;
item.Text = 195.ToString();
item.SubItems.Add(195);
item.SubItems.Add(Convert.ToString(char(195));
item.SubItems.Add(195.ToString());

But all my attempts failed. Could you give me an idea about how to add ASCII here?

Это было полезно?

Решение

195 is not in the ASCII range. Unfortunately there are many sites around which show "ASCII tables" containing characters over 127. These are often called "extended ASCII" - often with a false implication that there's only one such encoding. .NET uses Unicode - and each char is a UTF-16 code unit. So (char) 195 is actually U+00C3, which is a "Latin capital A with a tilde".

The character you were looking at wasn't even a tick - it was a square root sign.

For an actual tick, I suggest you want U+2713, which you'd add like this:

item.SubItems.Add = "\u2713";

Of course, that relies on the font you're using supporting that character.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top