0

I have a problem, a char is being inserted into a Dataset that I am trying to remove before the Dataset is being filled.

I have tried copying the Char and doing a String Match on it. It fails and gets inserted anyway.

The Char is:

also, I have one more:

'

My string matches:

if (KVP.Key != "'")
if (KVP.Key != " ")

Where KVP is the KeyValuePair in a Dictionary.

The only way I have thought of, to filter and remove is to convert the char's to the Unicode Code and look directly for that. Problem is, I can not find the Unicode Code.

I want to look for something like:

U+0061 = 'a'

if I use:

MessageBox.Show("U+" + char.GetNumericValue('a').ToString());

I get:

-1

then I can find the Char and match. I cannot find the conversion method for this procedure. Do I need a Lookup table with the Unicode Values? Or is there a C# Class already?

Rusty Nail
  • 2,692
  • 3
  • 34
  • 55
  • 1
    Possible duplicate of [How to recognize if a string contains unicode chars?](https://stackoverflow.com/questions/4459571/how-to-recognize-if-a-string-contains-unicode-chars) – Rufus L Nov 07 '18 at 22:21
  • Thanks but looking for char specific match, not if char is Unicode. – Rusty Nail Nov 07 '18 at 22:31
  • 1
    Maybe it's my browser (IE - at work), but your "The Char is:" and "also, I have one more:" code blocks are useless. The first is blank and the second is some kind of single-quote thing. What are you asking? Are you trying to figure out what the obscure character (that's in a string) that is messing you up? Iterate through the string and output each of the characters as a 4-digit hex value. That will give you the Unicode code-point values. – Flydog57 Nov 07 '18 at 22:36
  • There is a char in there, it is a blank char, apologies if you have misinterpreted the basis of the post! – Rusty Nail Nov 07 '18 at 22:38
  • I have the answer: MessageBox.Show(string.Format("U+{0:X4}", Convert.ToByte('a') )); I have to convert to a byte as string format and do a if x == a – Rusty Nail Nov 07 '18 at 22:39
  • 1
    I truly believe editing a Question to suit another's interpretation is a very inadequate way of resolving issues that the original OP has asked. When data is lost, the Question is no longer the same! – Rusty Nail Nov 07 '18 at 22:54

1 Answers1

0

well, it apprars as if a conversion to a byte solves the problem:

MessageBox.Show(string.Format("U+{0:X4}", Convert.ToByte('a') ));

I get:

U+0061

So I can now check at a byte to string level:

string a = string.Format("U+{0:X4}", Convert.ToByte('a'));
if (a.Equals("U+0061")) throw new Exception("Char Match: " + a);
Rusty Nail
  • 2,692
  • 3
  • 34
  • 55