REBOL [
    Title: "Divide on delimiter"
    Purpose: {Given a string known to have one delimiter in it
    somewhere, divide it into two parts at that delimiter.
    Return a block containing two strings, the first one being
    the text before the delimiter and the second one being
    the text after the delimiter.  The return strings are
    trimmed.}
]

;; [---------------------------------------------------------------------------]
;; [ This function was written for a very specific situation.                  ]
;; [ There was a text file with lots of lines like this example:               ]
;; [                                                                           ]
;; [     CV description: 3/4" Badger water meter, ser #xxxxxxxx, Rdg 0         ]
;; [                                                                           ]
;; [ We wanted to extract the "CV description" to use as a column heading      ]
;; [ in a spreadsheet, and the rest of the text as the column contents.        ]
;; [ This required dividing the line on the colon.  Care was taken to make     ]
;; [ sure there were no colons elsewhere.                                      ]
;; [ The function returns a block with the two strings, trimmed.               ]
;; [ As an added feature, the function accepts as input the delimiting         ]
;; [ character in case the function might have use for other situations.       ]
;; [---------------------------------------------------------------------------]

DIVIDE-ON-DELIMITER: func [
    INSTRING
    DELIM 
    /local PARTS WRDBLK
] [
    PARTS: copy []
    PARTS: parse/all INSTRING DELIM
    WRDBLK: copy []
    append WRDBLK trim first PARTS
    either second PARTS [
        append WRDBLK trim second PARTS
    ] [
        append WRDBLK ""
    ]
    return WRDBLK
]

;;Uncomment to test
;S1: {CV description: 3/4" Badger water meter, ser #xxxxxxxx, Rdg 0}
;S2: {CV description: }
;set [ID TXT] DIVIDE-ON-DELIMITER S1 ":"
;print ["ID=" mold ID ", TXT=" mold TXT]
;set [ID TXT] DIVIDE-ON-DELIMITER S2 ":"
;print ["ID=" mold ID ", TXT=" mold TXT]
;halt