Hi @JM64 , if I’m understanding correctly…
-
Any company whose name is longer than 40 characters needs to be split into two strings at the position of the last space that appears within the first 40 characters.
-
Any company whose name is less than 40 characters remains as a single string
You can achieve this by using String Manipulation nodes to find the position of the last space that appears within the first 40 characters, and then using subsequent String Manipulations to “substring” the string at that point. A Rule Engine can be included to handle the case where the name does not already exceed 40 characters:
String Manipulation - get length of company name:
(appends “CompanyNameLength” column)
length($Company Name$)
String Manipulation - find first space prior to position 40
(appends “lastSpaceBefore40” column)
lastIndexOfChar(substr($Company Name$,0,40),' ')
(not the use of single quotes in the above, rather than double quotes. This is a java thing to be aware of, and the lastIndexOfChar function takes as its last parameter a “char” rather than a “string”. Long story made short: this means it needs to be passed in single quotes)
Rule Engine - determine whether to use whole string or string up to located space
(appends “splitAtPosition” column)
$CompanyNameLength$ <= 40 => $CompanyNameLength$
TRUE => $lastSpaceBefore40$
String Manipulation - everything before split
(appends “CompanyName1” column)
strip(substr($Company Name$,0,$splitAtPosition$))
String Manipulation - everything after split
(appends “CompanyName2” column)
strip(substr($Company Name$,$splitAtPosition$+1))
Alternatively, in fewer nodes, this could also be achieved with just two String Manipulation nodes, using a more “codey” String Manipulation Hack, the conditional part of which you can find documented here, and builds all of the above logic. It does make it feel more like you are programming! …
String Manipulation for CompanyName1
string(
length($Company Name$)<=40
?$Company Name$
:strip(substr($Company Name$,0,
lastIndexOfChar(
substr($Company Name$,0,40)
,' ')
)
)
)
String Manipulation for CompanyName2
string(
length($Company Name$)<=40
?""
:strip(substr($Company Name$,
lastIndexOfChar(
substr($Company Name$,0,40)
,' ') +1
)
)
)
split string at last space prior to specific position.knwf (83.3 KB)