poncho Posted May 19, 2008 Report Share Posted May 19, 2008 Hi,I'm working on a BEncoding class in VB.NET. It works great but actually byte strings are read as byte arrays because there can be stored binary data (files hashes for example).How can I recognize a text string? Link to comment Share on other sites More sharing options...
jewelisheaven Posted May 19, 2008 Report Share Posted May 19, 2008 You can't? A basic check would be to see if it contains NULLs but even that isn't a good test... Ultima mentions this in the BFE thread http://forum.utorrent.com/viewtopic.php?pid=329008#p329008 You may want to pipe in there and ask. Link to comment Share on other sites More sharing options...
poncho Posted May 22, 2008 Author Report Share Posted May 22, 2008 OK, to differentiate between text strings and byte strings I do this:Byte strings are getting a NULL (0) at first position. Now I can easily differ between text and binary data. Link to comment Share on other sites More sharing options...
Ultima Posted May 23, 2008 Report Share Posted May 23, 2008 I'm not really seeing how that helps you to determine what's text and what's simply binary data... O_o Link to comment Share on other sites More sharing options...
poncho Posted May 23, 2008 Author Report Share Posted May 23, 2008 It's only for debugging. The program doesn't need it but it's easier for me because I can see what's in a variable as text and not as byte array. Link to comment Share on other sites More sharing options...
Burningmace Posted November 13, 2008 Report Share Posted November 13, 2008 Dunno if you're still working on this, but here's some pointers for you:Readable text has a whole range of characters - 0x0A and 0x0D for Line Feed and Carriage Return characters (newlines) and 0x20 (decimal 32) to 0x7E (decimal 126) for printable ASCII characters. So, if you want some code here it is:Function IsReadableText(data As Byte()) As Boolean For i As UInt64 = 0 To data.Length - 1 If Not ((data(i) >= 32 And data(i) <= 126) Or data(i) = 10 Or data(i) = 13) Then Return False End If Next Return TrueEnd FunctionIt's reasonably good performance too, as the instant a "non-readable" character is found it returns false. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.