I am looking to detect the row clicked and parse out the MAC ADDRESS. While I can split using RETURN and then Split using | OR REPLACEALL(" [INFO] Found: |", ββ), then SPLIT β|β but it starts getting messy but can make it work.
The important aspects I am looking for is the MAC and BLE NAMED DEVICE. In the above example return UNKNOWN
Is there a cleaner way to get the data the user clicked in MouseUp EVENT by the row clicked and then parse out MAC and DEVICE NAME?
dim lines() as string
rawData=ReplaceLineEndings(rawData, EndOfLine)
lines=rawData.Split(EndOfLine)
dim currentLineItems() as string
dim currentMACAddress as string
dim currentDeviceName as string
for each currentLine as string in lines
currentLine=Replace(currentLine, "[INFO] Found: |", "")
currentLine=Replace(currentLine, "| ", Chr(9))
currentLineItems=currentLine.Split(Chr(9))
'The array will contain the items in this order
'Extract them and then do something with them
currentMACAddress=currentLineItems(0)
currentDeviceName=currentLIneItems(1)
next
This could also be done with RegEx but since you have already gotten most of the way there with Replace, I thought Iβd stick with that.
Dim rx as new regex
Rx.searchpattern = "\|([0-9A-F:]+)\|"
Dim rm as regexmatch = rx.search(line)
Dim macaddress as string
If rm<>nil then
Macaddress=rm.SubExpressionString(1)
End if
Dim rx as new regex
Rx.searchpattern = "\|([0-9A-F:]+)\| (.+)$"
Dim rm as regexmatch = rx.search(line)
Dim macaddress as string
If rm<>nil then
Macaddress=rm.SubExpressionString(1)
DeviceName=rm.SubExpressionString(2)
End if
Regarding the clicked row. You could read the data, replace all lineendings with the UNIX lineending. Then split the data by EndOfLine.UNIX and present it in a Listbox. Then do the RegEx detection of the MAC Address and Device Name in the clicked row.
For the RegEx-Expression, i recommend (?Umi-s)\|([0-9A-F:]+)\|\s+\[?(.+)\]?\R
This one would also allow Device-Names starting with a Whitespace.
Please note that a line break must follow the last data line, otherwise the last data line will not be fully evaluated.
In the MouseUp Event of the TextArea you can get the content of the clicked row like this:
Var LineSelected As Integer = Me.LineNumber( Me.CharacterPosition( x, y ) )
Var Lines() As String = Me.Text.Split( "#" )
Var LineContent As String = Lines(LineSelected).Trim
(I used β#β as a splitter, because splitting by simple lineendings did not work. So i added a # after each line, within the TextArea.)
Instead of using a text area, could you instead output the lines to a list box?
Just normalize the line endings with ReplaceLineEndings and then split on EndOfLine.
That seems like it would make your life a lot easier in this case, unless that text area is serving other purposes as well and youβre just trying to add a unique feature to it.
This is the solution I have implemented which works while debugging with the RX portion to be used inline with BLE SCAN on final solution.
Var rawData As string
Var LineSelected As Integer = Me.LineNumber( Me.CharacterPosition( x, y ) )
Var Lines() As String = Me.Text.Split( EndOfLine)
If Not Lines.Count > 0 Then Return // Problem - POST ERROR
Var LineContent As String = Lines(LineSelected).Trim
Var rx As New regex
Var rm As regexmatch
Var Macaddress, DeviceName As String
rawData = ReplaceLineEndings(rawData, EndOfLine)
lines = rawData.Split(EndOfLine)
Rx.searchpattern = "\|([0-9A-F:]+)\| (.+)$"
rm = rx.search(LineContent)
If rm<>nil then
Macaddress = rm.SubExpressionString(1)
DeviceName = rm.SubExpressionString(2)
End if
I really need to understand how the two of you know how to format Rx.searchpattern
What both of you wrote resembles search patterns in CLID-ANI in TELCO industry for CALL PATTERNS. In those patterns [ ] indicates inlcude but in this it appears to be data when [ or ] is present. So the inclusion of first term and second term used in the search pattern syntax you wrote is different and is appears this β\|β is used to start a search term. If that is correct the rest of the formatting is less than 100% to me. What resource do you use to format search patterns?
Thank you to both for what is ultimately the final solution.
@Sascha_S while I have not come across this using bluetoothctl in ARM 64 I think this is significant as a user may add a whitespace and not know it or on purpose. For the use I need I am creating the BLE LOCAL NAME and will only be looking for that. So when I move to looking at all BLE LOCAL NAMES in other efforts this will be a handy resource. Thank you