4 Replies - 408 Views - Last Post: 01 January 2013 - 01:56 PM Rate Topic: -----

#1 davers  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 62
  • Joined: 07-April 11

Parse text after converting from binary

Posted 01 January 2013 - 01:07 PM

Hey Gang!

I'm pulling a Binary attribute from an LDAP file and converting into text using the following code:

            PropertyValueCollection propCol = de.Properties["deftyVectorSteps"];

            byte[] data = (byte[])propCol.Value;

            System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
            string str = enc.GetString((System.Byte[])propCol.Value);


For now, I'm exporting it to a text file so I can see what it looks like. I've attached the text file so you can see what I'm dealing with. The problem is, I'm not sure what the characters are I'm supposed to be parsing on. The characters look like black triangles with a question mark in the center of it. Also I'll see a triangle with a capital D or R after it. I'm not sure what I'm looking at. I've attached the file so you can see what I'm talking about. I need to parse it so it looks like the second file I've attached, and I need to remove those weird characters. There's much much more to what I need to do besides the parsing, but for now, that's where I'm stuck. Can anyone give me any guidance?

Thanks!

Dave

Attached File(s)



Is This A Good Question/Topic? 0
  • +

Replies To: Parse text after converting from binary

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3666
  • View blog
  • Posts: 11,497
  • Joined: 05-May 12

Re: Parse text after converting from binary

Posted 01 January 2013 - 01:18 PM

In your code above, on line 3, you get the value as a byte array, and then you do it again on line 5. Why not just use the bytes from line 3?
Was This Post Helpful? 0
  • +
  • -

#3 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3666
  • View blog
  • Posts: 11,497
  • Joined: 05-May 12

Re: Parse text after converting from binary

Posted 01 January 2013 - 01:27 PM

You should get in touch with Avaya to ask how to parse that data in that binary property.

Are you sure that the byte array must be decoded as UTF-8? What if it really is a binary blob with header and field information rather than a text string?

This post has been edited by Skydiver: 01 January 2013 - 02:07 PM
Reason for edit:: Fixed typo.

Was This Post Helpful? 0
  • +
  • -

#4 davers  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 62
  • Joined: 07-April 11

Re: Parse text after converting from binary

Posted 01 January 2013 - 01:41 PM

Hm..turns out it's Ascii.. this seems to work:

            PropertyValueCollection propCol = de.Properties["deftyVectorSteps"];

            System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
            string str = enc.GetString((System.Byte[])propCol.Value);


Now it just leaves a question mark where I need to parse. Now the question is, how do I parse on the question mark and start a new line after each question mark. All the parsing I've ever done the text is already multiple lines.

Thanks for looking,

Dave
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3666
  • View blog
  • Posts: 11,497
  • Joined: 05-May 12

Re: Parse text after converting from binary

Posted 01 January 2013 - 01:56 PM

If you don't care about efficiency, this may give you an idea:
string input = "Hello?World?";
Console.WriteLine(input);
input = input.Replace("?", Environment.NewLine);
Console.WriteLine(input);


Was This Post Helpful? 1
  • +
  • -

Page 1 of 1