‎2019 Aug 20 11:56 AM
Hey guys,
first of all forgive my English, but I need your help with this.
I need to split a string by the second repetition of an hyphen, I know, I explain myself badly, but I give an example:
my string is like this:
CO-CODA (CODE) TA - 8 hours (500)
and I need it to be like this:
CO-CODA (CODE) TA
8 hours (500)
thanks
‎2019 Aug 20 5:01 PM
As mentioned by Sandra you can do it by many ways. Here is how you will do it by Split keyword.
First split the string into three strings at the hyphen. (Str1, Str2, Str3)
Then concatenate the first two part (Str1, Str2) into result string separated by hyphen.
DATA text TYPE string.
text = `CO-CODA (CODE) TA - 8 hours (500)`. "Example Text
SPLIT text AT '-' INTO: DATA(str1) DATA(str2) DATA(str3).
CONCATENATE str1 str2 INTO DATA(result) SEPARATED BY '-'.
WRITE:/ result.
‎2019 Aug 20 12:06 PM
You can do it in many ways, for example with SPLIT, segment, substring_before, match, and so on.
‎2019 Aug 20 12:27 PM
and if I don't know how many hyphens are in the string, how can I separate them in a way to have all the string until the last hyphen?
‎2019 Aug 20 12:59 PM
‎2019 Aug 20 12:40 PM
‎2019 Aug 20 5:01 PM
As mentioned by Sandra you can do it by many ways. Here is how you will do it by Split keyword.
First split the string into three strings at the hyphen. (Str1, Str2, Str3)
Then concatenate the first two part (Str1, Str2) into result string separated by hyphen.
DATA text TYPE string.
text = `CO-CODA (CODE) TA - 8 hours (500)`. "Example Text
SPLIT text AT '-' INTO: DATA(str1) DATA(str2) DATA(str3).
CONCATENATE str1 str2 INTO DATA(result) SEPARATED BY '-'.
WRITE:/ result.