New call-to-action
Results 1 to 5 of 5

Thread: string puzzle

  1. #1
    Member Chris.Tanti's Avatar
    Real Name
    Chris Tanti
    Join Date
    May 2000
    Location
    Cardiff, South Wales, UK
    Posts
    368

    Default string puzzle

    Can any one offer a pointer to solving this little prob.

    Have a string field that contains a list of names (various numbers, seperated by a comma) Eg.

    Record 1: Mike, Alan, John
    Record 2: Tony
    Record 3: Emma, Marrie
    Record 4: John, Peter, David, Andrew

    I want to change the field so it contains the following

    Record 1: Mike, Alan and John
    Record 2: Tony
    Record 3: Emma and Marrie
    Record 4: John, Peter, David and Andrew

    Any ideas appreciated, Thanks!

  2. #2
    Member
    Real Name
    Steve Andrews
    Join Date
    Jan 2004
    Location
    Mahwah, NJ
    Posts
    644

    Default RE: string puzzle

    strng="Mike"
    ?if(at(",",strng)=0,strng,*reverse(strtran(*reverse(strng),",","dna ",1,1)))
    = "Mike"

    strng = "John, Peter, David, Andrew"
    ?if(at(",",strng)=0,strng,*reverse(strtran(*reverse(strng),",","dna ",1,1)))
    = "John, Peter, David and Andrew"

  3. #3
    "Certified" Alphaholic
    Real Name
    Tom Cone Jr
    Join Date
    Apr 2000
    Location
    Florida
    Posts
    23,322

    Default RE: string puzzle

    Another approach:

    teststring = "Bill, John, Mary"

    ?occurs(",",teststring)
    = 2

    ?at(",",teststring,2)
    = 11

    ?substr(teststring,1,11)
    = "Bill, John,"

    ?len(trim(teststring))
    = 16

    ?right(teststring,16-11)
    = " Mary"

    ?if(occurs(",",teststring)= 0, teststring, substr(teststring,1,at(",",teststring,occurs(",",teststring)))+" and" + right(teststring,len(trim(teststring))- at(",",teststring,occurs(",",teststring))))
    = "Bill, John, and Mary"



    -- tom

  4. #4
    "Certified" Alphaholic Stan Mathews's Avatar
    Real Name
    Stan Mathews
    Join Date
    Apr 2000
    Location
    Bowling Green, KY
    Posts
    25,119

    Default RE: string puzzle

    teststring = "John, Peter, David, Andrew"
    ? stritran(teststring,","," and",w_count(teststring,", ")-1,1)
    = "John, Peter, David and Andrew"

  5. #5
    Member Chris.Tanti's Avatar
    Real Name
    Chris Tanti
    Join Date
    May 2000
    Location
    Cardiff, South Wales, UK
    Posts
    368

    Default RE: string puzzle

    Wow,

    Thanks for the varied response (always fascinating to see how others approach problems with the same tools)

    After the initial hour of mental block I came up with this (about 5mins after submitting the cry for help!)

    left(teststring,at(',',teststring,-1)-1)+' and'+right(teststring,len(teststring)-at(',',teststring,-1))

    But looks like theres some much shorter and cleaner methods than this, thank you for the input as always.

Similar Threads

  1. A New Year puzzle...
    By Paul H in forum Alpha Four Versions 7 and 8
    Replies: 1
    Last Post: 02-16-2005, 11:49 PM
  2. Scripting Puzzle
    By Tim Madison in forum Alpha Five Version 5
    Replies: 4
    Last Post: 05-18-2004, 02:27 PM
  3. Formula Puzzle
    By Bill Feldhaus in forum Alpha Five Version 5
    Replies: 13
    Last Post: 11-13-2003, 06:24 AM
  4. Puzzle 2
    By Tom Cone Jr in forum Alpha Five Version 4
    Replies: 9
    Last Post: 04-16-2001, 06:36 AM
  5. Puzzle question for Tom
    By Jeff Moses in forum Alpha Five Version 4
    Replies: 1
    Last Post: 04-12-2001, 02:44 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •