July 14, 201015 yr I am using a serial plugin to receive data into a field, I need to manipulate this data so that I get the most recently received reading each time. The data feeds into a holding field, when it populates into the field it appears as either 1 reading, 2 readings or 3 readings at a time with the newest one being the last one to appear in the field. Each reading has a leading and ending identifier (I can't enter them here as the character set isn't supported). The data looks like this: 3.156G 4.541G The leading identifier, 3 spaces, THE DATA I WANT, a G and an ending identifier. Going by the above, my end result would be "4.541" Can anyone help me out with how I will get the data required. I am using the Troi Serial Plugin
July 14, 201015 yr Let( values = Substitute ( Trim ( YourField ) ; " " ; ¶ ) ; GetValue ( values ; ValueCount ( values ) ) )
July 14, 201015 yr That wouldn't drop the 'G' off the end. Another possible option would be: GetAsNumber ( RightWords ( field ; 1 ) )
July 14, 201015 yr Or Filter( RightWords( field ; 1 ) ; "01234567890." ) Isn't there some point in using the layout pulled formatting, the dot makes hardly any point if the receiving field is number, but could make a hell of a difference if the system setting is other than "new world" default. --sd
July 14, 201015 yr You could use = GetAsNumber ( RightWords ( field ; 1 ) ) However, if you are using a comma as your decimal separator, and the input data contains a dot instead (as shown in the OP example) you already have a problem. --- Oops - didn't see LaRetta already suggested this. Edited July 14, 201015 yr by Guest
July 14, 201015 yr I didn't use a calculation based on the GetAsNumber( ) function because nobody said that an identifier must be a number. What if his system has the comma as a decimal separator, but the identifier isn't a number ( only a sequenze of digit and dots ) ? Also I didn't discard the G because he said: "THE DATA I WANT, a G and an ending identifier." that isn't exactly the same of their next: "Going by the above, my end result would be "4.541"
July 14, 201015 yr ... and now I remember why I didn't use RightWords ( )... If the identifier was a decimal number starting with a dot ?
July 14, 201015 yr If the identifier was a decimal number starting with a dot ? Doesn't seem very likely: Each reading has a leading and ending identifier (I can't enter them here as the character set isn't supported). But it would be better if the OP clarified this point.
July 14, 201015 yr "The leading identifier, 3 spaces, THE DATA I WANT, a G and an ending identifier." I read that this is the description of the sequence of how the characters will appear ... the leading identifier, 3 spaces, THE DATA HE WANTS, then a G and an ending identifier. It was clearly indicated the final result of 4.541. BTW, GetAsNumber() drops invalid characters at the beginning, middle or end since FM sees numbers only (or as indicated by Michael, a comma if the OS was so inclined). Invalid characters are not seen as word separators either. RightWords() applied to 313.44 417.22445G would automatically drop the first invalid character because it does not see it as a character. 313.44 417.22445G would be considered two words (only because of the space between) and the calculation I provided will give the result of 417.22445. You can go on until the cows come home but we can only go by the information presented. If the person presenting the data doesn't provide all possible strings then it is their responsibility to come back and provide further detail. Also, a period or dash does NOT belong to invalid character set as was indicated by "Each reading has a leading and ending identifier (I can't enter them here as the character set isn't supported). And sorry, Michael, my response was more directed towards Daniele but overall I was speaking to the both of you. :laugh2: Edited July 14, 201015 yr by Guest
July 14, 201015 yr I sure misunderstood the sequence and what he considered an identifier. So now, thanks to LaRetta, I understand that the string could be: [LeadingIdentifier][3spaces][TheData][G][EndingIdentifier][LeadingIdentifier][3spaces][[color:red]TheDataHeWants][G][EndingIdentifier] In this case RightWords ( string ; 1 ) may give incorrect value if: [[color:red]TheDataHeWants] starts with a dot [[color:red]TheDataHeWants] ends with a dot The lone sure thing is that there are 3 spaces before the last part of the string. So my calc could be modified to: Let( values = Substitute ( Trim ( YourField ) ; " " ; ¶ ) ; Substitute ( GetValue ( values ; ValueCount ( values ) ) ; [ "G" ; "" ] ; [ "EndingIdentifier" ; "" ] ) ) This can evaluate correctly a string like: 313.44G .44G or 313.44G 31344.G
July 14, 201015 yr RightWords ( string ; 1 ) may give incorrect value if: [[color:red]TheDataHeWants] starts with a dot Right. Good catch.
July 14, 201015 yr It might be nice to hear back from the OP. He hasn't been back since he posted his question. Lee
July 14, 201015 yr OP is 'other person', original poster or sometimes called On Point. I'm joking of course ... it can stand for many things just as LOL can stand for different things. Here's where you will find the answers Edited July 14, 201015 yr by Guest
July 14, 201015 yr Thank you. I like: Old Patient OutPatient because some times the OP needs to be patient with us till he becomes old. ( or, like an OutPatient, must come many times to the Forum/Hospital ) :
Create an account or sign in to comment