-1

For C# people easy question, VB.NET syntax equivalent of:

wlanBssEntries.Sort(delegate ( Wlan.WlanBssEntry a, Wlan.WlanBssEntry b ) {
                            return sortModifier * string.Compare(ASCIIEncoding.ASCII.GetString(a.dot11Ssid.SSID),
                                ASCIIEncoding.ASCII.GetString(b.dot11Ssid.SSID), StringComparison.InvariantCultureIgnoreCase);
                        });

Thanks a lot.

theduck
  • 2,589
  • 13
  • 17
  • 23
Jerry
  • 33
  • 4
  • 3
    Aside: SSIDs are [UTF-8, not always ASCII](https://stackoverflow.com/a/28450037/634824), and [the docs for the `DOT11_SSID` structure](https://learn.microsoft.com/en-us/windows/win32/nativewifi/dot11-ssid) explain that the SSID is *not* a null-terminated ASCII string - thus you shouldn't treat it as one. Instead, use `Encoding.UTF8.GetString(a.dot11Ssid.SSID, 0, (int) a.dot11Ssid.SSIDLength)` as seen [here](https://social.technet.microsoft.com/wiki/contents/articles/39587.c-managed-wifi-api.aspx). – Matt Johnson-Pint Dec 30 '19 at 18:30
  • @Matt: my structure is defined as Public Structure Dot11Ssid Public SSIDLength As UInteger Public SSID As Byte() End Structure – Jerry Dec 30 '19 at 18:48
  • You can find code converters if you search for C# to VB.NET. This one seems to work for your case https://codeconverter.icsharpcode.net. I recommend looking into https://stackoverflow.com/help/how-to-ask – Slai Dec 30 '19 at 18:51
  • @Jerry - Exactly. You need to use that `SSIDLength` property. Don't just ignore it. – Matt Johnson-Pint Dec 30 '19 at 19:29

1 Answers1

1

working syntax is:

wlanBssEntries.Sort(Function(a As wlan.WlanBssEntry, b As wlan.WlanBssEntry) sortModifier * String.Compare(ASCIIEncoding.ASCII.GetString(a.dot11Ssid.SSID), ASCIIEncoding.ASCII.GetString(b.dot11Ssid.SSID), StringComparison.InvariantCultureIgnoreCase))
Jerry
  • 33
  • 4
  • 1
    As suggested, use `Encoding.UTF8.GetString()`. If the SSID is ASCII encoded, UTF8 will read it as-is, since it maps the ASCII table 1:1 (one byte per char). If it's UTF8 encoded, `Encoding.ASCII.GetString()` will return garbage. – Jimi Dec 30 '19 at 19:20