Graphics

 View Only
  • 1.  Parsing Data Via Scripting

    Posted 12-07-2023 12:53

    Hoping someone might be able to help me with a script I've been trying to write for a few days now and not having any luck. I am trying to parse some data and feed it into 4 different text objects to alleviate the operator having to manually type in the data.

    Data Example: xxxxxxxxxxxxxxxxx (yyyyyyy) (11-22, 3:33)

    I want to do the following:

    text1: xxxxxxxxxxxxxxxxx (yyyyyyy)
    text2: 11
    text3: 22
    text4: 3:33



    ------------------------------
    Dalton
    Senior Graphics Producer
    ------------------------------


  • 2.  RE: Parsing Data Via Scripting

    Posted 12-07-2023 14:31

    Did a quick test and this worked. You want Regular Expressions. Very Powerful.

    https://learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference

    First, add this to your Global Scripts.

    Function RegExpReplace(src as String, rgx as String, rplc as String)
      Dim rObj as Object
      Dim rez as String
      rObj = CreateObject("VBScript.RegExp")
      rObj.Pattern = rgx
      rObj.Global = True
      rez = rObj.Replace(src,rplc)
      RegExpReplace = rez
    End Function

    Then I put this in the "On Prepare" event.

    Dim src as xpTextObject, txt as xpTextObject
    
    Self.GetObjectByName("src",src)
    Self.GetObjectByName("Text1",txt)
    txt.Text=RegExpReplace(src.Text,"^([^\)]*\)).*","$1")
    Self.GetObjectByName("Text2",txt)
    txt.Text=RegExpReplace(src.Text,"^.*\([ ]*([\d]*).*","$1")
    Self.GetObjectByName("Text3",txt)
    txt.Text=RegExpReplace(src.Text,"^.*\([ ]*[\d]*-([\d]*).*","$1")
    Self.GetObjectByName("Text4",txt)
    txt.Text=RegExpReplace(src.Text,"^.*\(.*,[ ]*([^\)]*).*","$1")

    Assuming that format never changes, this should work.



    ------------------------------
    Azathoth
    Son of Cthulhu
    ------------------------------



  • 3.  RE: Parsing Data Via Scripting

    Posted 12-09-2023 12:56

    Thank you for this! It worked perfectly. I definitely need to do some research to fully understand what you did to make this work.

    Greatly appreciate it!



    ------------------------------
    Dalton
    Senior Graphics Producer
    ------------------------------



  • 4.  RE: Parsing Data Via Scripting

    Posted 12-11-2023 10:02

    Regular Expressions are ridiculously powerful and slippery to master, but worth the effort.

    Bash - Sed - Awk : the trinity of text parsing.



    ------------------------------
    Azathoth
    Son of Cthulhu
    ------------------------------



  • 5.  RE: Parsing Data Via Scripting

    Posted 12-22-2023 17:02

    Upon further testing, I realized the longer my data (xxxxxxxxxxxxxxxxx (yyyyyyy) (11-22, 3:33)) gets the more messed up it becomes. How would you adjust it if the text was something along the lines of:


    New Data Example: F. PlayerName 18 yard Touchdown, pass from S. PlayerName (T. PlayerName kick is good) (11-22, 3:33)
    text1: F. PlayerName 18 yard Touchdown, pass from S. PlayerName (T. PlayerName kick is good)
    text2: 11
    text3: 22
    text4: 3:33



    ------------------------------
    Dalton
    Senior Graphics Producer
    ------------------------------



  • 6.  RE: Parsing Data Via Scripting

    Posted 12-22-2023 17:34

    I do not see what is messed up. It looks like it gave the desired results.

    Also, if the end portion is (11:22, 3:33) it would screw up because it is expecting (11-22, 3:33). It requires the dash.

    Unfortunately I will be out of pocket till the day after Christmas and won't be ale to help.



    ------------------------------
    Azathoth
    Son of Cthulhu
    ------------------------------