0

I have the following problem

I am using an SDK that returns values form a database.

The value i need is 4, 6, 7 but the SDK returns "\u0004","\u0006","\u0007" I was wondering if there is a way to check if it is "\u0004","\u0006","\u0007" or any way of doing this?

I Have the following code (C#):

Line_Type = Line_Type.Replace(@"\u000", "");
if (Line_Type == "4")
{
    Line_Type = "4";
}
else if (Line_Type == "6")
{
    Line_Type = "6";
}
else if (Line_Type == "7")
{
    Line_Type = "7";
}

I have tried multiple ways to get the done but can't find a right way to get this done.

I Have google but can't find anything.

Andre Hoffmann
  • 362
  • 1
  • 4
  • 12
  • not sure I understand your question, but your code seems to have a few problems: the code within ifs is pointless: `if variable == something variable = something`. also, you are stripping "\u000" from every value of Line_Type, which maybe is not what you want to do – Gian Paolo Nov 23 '15 at 08:42
  • yes sorry i have an error in the copying and pasting. In short what i want is to strip \u000 from the Line_Type so that i can only get 4, 6, 7 as a string – Andre Hoffmann Nov 23 '15 at 08:43

2 Answers2

4

From your question I understood that SDK returns values in unicoded style. Then you can use the following code to convert unicode values to respective decimal value.

char uniCodeValue = char.Parse(Line_Type);//  '\u0004' unicode values
int decimalValue = uniCodeValue;
Console.Write(decimalValue.ToString()); // prints 4

Hope your problem got solved!!

Andre Hoffmann
  • 362
  • 1
  • 4
  • 12
Nikson K John
  • 455
  • 5
  • 13
0

In your replace call, "\u" is considered as an escape char. if you use double \, you get the string "\u0009"; check the difference between these two:

Console.WriteLine ("\u0009");
Console.WriteLine ("\\u0009");

the second print the string you are trying to replace with an empty string.

Gian Paolo
  • 4,161
  • 4
  • 16
  • 34
  • Sr as this problem is already solved, but ur error mentioned was wrong. The author type an @ sign before the string which means that \ sign is no longer considered as a Escape Sign. – Yosh Synergi Nov 23 '15 at 09:05
  • right, I missed it. I just upvoted Nikson answer, that actually is the solution for you problem – Gian Paolo Nov 23 '15 at 09:07