B4J Question Need help parsing this information

Mark Read

Well-Known Member
Licensed User
Longtime User
Here is a typical example of data I need to parse:

nif((OPCclient1.'2500-2'.'192-168-1-120-502-ID002-2584'.IO.Module12.M12_C1.Val)or (\\.\EEMethan_Display\sw_Override_value),1,0),OPCclient1.'2500-2'.'192-168-1-120-502-ID002-2584'.IO.Module12.M12_C1.Val>0, green, \\.\EEMethan_Display\sw_Override_value>0, orange, ,blue, , blue, , blue, red


From this I need to get an array containing:

nif((OPCclient1.'2500-2'.'192-168-1-120-502-ID002-2584'.IO.Module12.M12_C1.Val)or (\\.\EEMethan_Display\sw_Override_value),1,0)

OPCclient1.'2500-2'.'192-168-1-120-502-ID002-2584'.IO.Module12.M12_C1.Val>0

green

\\.\EEMethan_Display\sw_Override_value>0

orange

""

blue

""

blue

blue

red

I tried using regex.split on the comma but did not see the commas in the first item. Can anyone help?
 

stevel05

Expert
Licensed User
Longtime User
If the format is always identical you could rebuild the first string from the first three array elements.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Unfortunately it can be more complicated. But you have given me an idea. Only the first field is so complex. In theory I could work backwards and read the last nine fields and then remove them from the base string.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
Another option:

B4X:
    Dim Result As List
    Result.Initialize
    Dim Test As String = "nif((OPCclient1.'2500-2'.'192-168-1-120-502-ID002-2584'.IO.Module12.M12_C1.Val)or (\\.\EEMethan_Display\sw_Override_value),1,0),OPCclient1.'2500-2'.'192-168-1-120-502-ID002-2584'.IO.Module12.M12_C1.Val>0, green, \\.\EEMethan_Display\sw_Override_value>0, orange, ,blue, , blue, , blue, red"
    Dim Str() As String = Regex.Split(",O",Test)
   
    Result.Add(Str(0))
   
    For Each S As String In Regex.Split(",",Str(1))
        If S.StartsWith("PCclient") Then
            Result.Add("O" & S)
        Else
            Result.Add(S)
        End If
    Next
   
    For Each S As String In Result
        Log(S)
    Next
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
From this I need to get an array containing
I managed to get quite close:
B4X:
Dim s As String = $"nif((OPCclient1.'2500-2'.'192-168-1-120-502-ID002-2584'.IO.Module12.M12_C1.Val)or (\\.\EEMethan_Display\sw_Override_value),1,0),OPCclient1.'2500-2'.'192-168-1-120-502-ID002-2584'.IO.Module12.M12_C1.Val>0, green, \\.\EEMethan_Display\sw_Override_value>0, orange, ,blue, , blue, , blue, red"$
Dim split() As String = Regex.Split(",(?![^(]*\))", s)
For Each r As String In split
    Log(r)
Next
(coma, can be followed by anything but a closing parenthesis)
returns
B4X:
nif((OPCclient1.'2500-2'.'192-168-1-120-502-ID002-2584'.IO.Module12.M12_C1.Val)or (\\.\EEMethan_Display\sw_Override_value),1,0)
OPCclient1.'2500-2'.'192-168-1-120-502-ID002-2584'.IO.Module12.M12_C1.Val>0
green
\\.\EEMethan_Display\sw_Override_value>0
orange

blue

blue

blue
red
but I can't get the "" (double - double quotes). Where do they come from? or did you mean that that array index should be empty?

by the way, I recommend www.regexpal.com for this kind of work.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
but I can't get the "" (double - double quotes). Where do they come from? or did you mean that that array index should be empty?
Yes the entry is empty.

What is generating the data ?
The data is generated by a data acqusition program.

I have since tried various files and have found that the data can have 12, 13 or 14 BASIC parts. If the command nif is used (if with a numeric result), then it causes problems with a regex split on the comma.

I have a long winded solution. I split on the comma and work backwards, starting with "red". I then remove each entry from the basic string and what is left is the first string as required. I have tried this also with nested nif statements which can use many lines and it works.

I will post the code next week as it is on my work PC. Many thanks for the help.

Steve's idea was great.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
Just having a quick look -
1. Are you allowed remove all space.
2. The 'or' condition, is this usually accompanied with the nif command.
3. Are the '.' dots are field separators with the OPCclient1

Regards

John.
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
1. Are you allowed remove all space.
2. The 'or' condition, is this usually accompanied with the nif command.
3. Are the '.' dots are field separators with the OPCclient1

1. Yes, spaces are not required
2. No but there can be multiple nif an/or or statements
3. No, this is one field in the form: OPCClient1.OPCServerName.IP-Address.ParameterSource.ModuleDescription.ModuleNumber.ChannelNumber.Property. Each "Server" has thousands of properties.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
1. Yes, spaces are not required
2. No but there can be multiple nif an/or or statements
3. No, this is one field in the form: OPCClient1.OPCServerName.IP-Address.ParameterSource.ModuleDescription.ModuleNumber.ChannelNumber.Property. Each "Server" has thousands of properties.
So it would be true to say that you need to parse out the 'server data' and the value for it ?
 
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
So it would be true to say that you need to parse out the 'server data' and the value for it ?
NO, that would take too long. The server offers tens of thousands of parameters in 100ms intervals. My data comes from the OPCclient but indirectly.

To try and explain. I am using an industry grade data acqusition hardware and a visualisation software from an american company. Normally it would be a case of loading the required driver into the software and communicating with the hardware directly. In this case, there is no driver. A workaround is to use an OPC server software from the hardware company, which interacts, both input and output, with windows. The visualisation software then uses an OPC client to grab the data from the server (again, both input and output). This means, the server and the client are on the same machine!.
A newer version of the visualisation software is not available as they have stopped developing. From the same company, there is another software which is much more complicated to learn and uses virtual wiring compared to my software which uses objects.

The data I am trying to extract is the configuration file for the objects in a process file.

The data in post #1 is the configuration for 1 single gauge in the process. The first item is the raw signal and the rest are the options, color change on various conditions etc.
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
Upvote 0

Mark Read

Well-Known Member
Licensed User
Longtime User
Could you explain why the one I suggested is not what you need?
@jmon: I did not say that is not what I need. I needed time to test it on my work PC. Indeed, it works great. I have checked with some examples which I have and it works well. Will keep on testing.

I also got a little sidetracked with the explanation for Jmu5667.

I will change my code accordingly. I am not very good with Regex. Thanks for your help. Credit where credit is due. There is nearly always more than one solution but some are shorter/easier than others.
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
I did not say that is not what I need
No worries ! :) I thought I may have not understood your problem, that's why I asked for clarification! I'm happy to see that it helped you
 
Upvote 0

PABLO2013

Well-Known Member
Licensed User
Longtime User
Regards...i used it

B4X:
        T1=Mid( text1, text1.IndexOf("var productPriceWithoutReduction ="),100)
            T5=Mid(T1,0,T1.IndexOf(";")).Replace("var productPriceWithoutReduction =","").Replace(".",",").Trim
            Log(T5)


B4X:
Sub Mid(Text As String, Start As Int, Length As Int) As String
   If Length>0 And Start>-1 And Start< Text.Length Then Return Text.SubString2(Start,Start+Length)
End Sub
 
Upvote 0
Top