Discussions

Expand all | Collapse all

How to Capture Parts of a Long String

  • 1.  How to Capture Parts of a Long String

    Posted 05-04-2017 17:30
    I have a string "FirstName_John_LastName_Smith_Job_Programmer"

    I would like to capture with formula text fields

    First Name: "John"
    Last Name: "Smith"
    Job: "Programmer"

    I've tried playing around with Part Formula with limited success

    Is this possible?


  • 2.  RE: How to Capture Parts of a Long String

    Top
    Contributor
    Posted 05-04-2017 17:55
    Try this in your formula text field.

    "First Name: "&Part([String], 2, "_")&"<br>
    Last Name: "&Part([String], 4, "_")&"<br>
    Job: "&Part([String], 6, "_")

    This worked when I tested with your example.  Make sure to enable html so you get the line breaks


  • 3.  RE: How to Capture Parts of a Long String

    Top
    Contributor
    Posted 05-04-2017 17:57


  • 4.  RE: How to Capture Parts of a Long String

    Posted 05-04-2017 18:00
    Sorry I wasnt clear...
    each section would be its own formula text field.

    First Name would be its own formula text field and i want it to return "John"
    Last Name would be its own formula text field and it would return "Smith"

    I also want the format of the string not to matter.. meaning I could pass in the string 

    "Job_Programmer_LastName_Smith_FirstName_John" and it would return the same results


  • 5.  RE: How to Capture Parts of a Long String

    Posted 05-05-2017 01:48
    ... I suspect that is going to be very difficult and likely impossible with native QuickBase.  You will need a non native script.


  • 6.  RE: How to Capture Parts of a Long String

    Top
    Contributor
    Posted 05-05-2017 02:22
    >... I suspect that is going to be very difficult and likely impossible with native QuickBase. 

    It is simple:

    Formula for [First Name] =
    If(
      Part([String], 1, "_") = "FirstName", Part([String], 2, "_"),
      Part([String], 3, "_") = "FirstName", Part([String], 4, "_"),
      Part([String], 5, "_") = "FirstName", Part([String], 6, "_")
    )
    Formula for [Last Name] =
    If(
      Part([String], 1, "_") = "LastName", Part([String], 2, "_"),
      Part([String], 3, "_") = "LastName", Part([String], 4, "_"),
      Part([String], 5, "_") = "LastName", Part([String], 6, "_")
    )

    Formula for [Job] =
    If(
      Part([String], 1, "_") = "Job", Part([String], 2, "_"),
      Part([String], 3, "_") = "Job", Part([String], 4, "_"),
      Part([String], 5, "_") = "Job", Part([String], 6, "_")
    )


  • 7.  RE: How to Capture Parts of a Long String

    Top
    Contributor
    Posted 05-05-2017 02:57
    We were both working on this at the same time. 


  • 8.  RE: How to Capture Parts of a Long String

    Posted 05-05-2017 02:30
    Yes, in fact that was simple!  I missed that solution.


  • 9.  RE: How to Capture Parts of a Long String

    Top
    Contributor
    Posted 05-05-2017 02:49
    Oh where is your imagination Mark....


    //Break the individual parts out
    var text PartOne=Part([String], 1, "_")&Part([String], 2, "_");
    var text PartTwo=Part([String], 3, "_")&Part([String], 4, "_");
    var text PartThree=Part([String], 5, "_")&Part([String], 6, "_");
    //Conditional to find the first name in the string
    var text FirstName=If(Contains($PartOne, "First"), "First Name: "&Part([String], 2, "_"), 
    If(Contains($PartTwo, "First"), "First Name: "&Part([String], 4, "_"),
    If(Contains($PartThree, "First"), "First Name: "&Part([String], 6, "_"),
    "No First Name")));
    //Conditional to find the last name in the string
    var text LastName=If(Contains($PartOne, "Last"), "Last Name: "&Part([String], 2, "_"), 
    If(Contains($PartTwo, "Last"), "Last Name: "&Part([String], 4, "_"),
    If(Contains($PartThree, "Last"), "Last Name: "&Part([String], 6, "_"),
    "No Last Name")));
    //Conditional to find the job in the string
    var text Job=If(Contains($PartOne, "Job"), "Job: "&Part([String], 2, "_"), 
    If(Contains($PartTwo, "Job"), "Job: "&Part([String], 4, "_"),
    If(Contains($PartThree, "Job"), "Job: "&Part([String], 6, "_"),
    "No Job")));
    //Combine them into the desired list
    List("<br>", $FirstName, $LastName, $Job)

    It works with any and all combos.  Just as long as the string is divided by the "_" and maintains the format you proposed


  • 10.  RE: How to Capture Parts of a Long String

    Top
    Contributor
    Posted 05-05-2017 02:50
    ">https://d2r1vs3d9006ap.cloudfront.net/s3_images/1592226/RackMultipart20170505-64330-1gly7pz-Screen_Shot_2017-05-04_at_8.45.20_PM_inline.png?1493952600">">https://d2r1vs3d9006ap.cloudfront.net/s3_images/1592227/RackMultipart20170505-98582-v1jwy-Screen_Shot_2017-05-04_at_8.45.54_PM_inline.png?1493952608">