Skip to Content
author's profile photo Former Member
Former Member

How do I select all text in a string BEFORE the last space?

Hi,

I have a text field (60 characters max) that needs to be split into two fields 40 char and 20 char. The data is a Vendor Name and therefore can't just be trimmed at 40 since that might cause a word to be cut off.

I can get the last full word of the name where the name is over 40 characters, but I need the full text before the last space in the 40 Character field

Example:

International Department of Labour and Internal Relations

Field 1 should read: International Department of Labour and

Field 2 should read: Internal Relations

How can I extract the data for Field 1

This is how I got Field 2:

Formula 1 -

left ({VENDOR.NAME},40)

Result : "International Department of Labour and I"

Formula 2 -

if len({VENDOR.NAME})>40 then

if instr({@Form 1}," ") > 0 then

split({@Form 1}," ")[ubound(split({@Form 1}," "))] else

{@Form 1}

else ''

Result: "I"

Formula 3

Mid ({VENDOR.NAME},41 )

Result "nternal Relations"

Formula 4

if {@form 2} = '' then '' else

{@Form 3}+{@form 2}

Result: "Internal Relations"

Thanks in Advance,
Denise

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Posted on Jun 27, 2016 at 07:42 PM

    There actually might be an easier way to do this:

    {@First}

    NumberVar nAt := Length({VENDOR.NAME});

    StringVar result := {VENDOR.NAME};

    While (nAt > 40) do

    {

    nAt := InStrRev(result, " ");

    result := left(result, nAt);

    }

    result

    {@Second}

    LTrim(Replace({VENDOR.NAME}, {@First}, ""))

    -Dell

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.