Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

SOLVED

Select text between two symbols

awmackenzie
Level 2
Level 2

I have a table that gets populated with different strings of text. Sometimes there will be lines of text that are surrounded by a "|" (pipe) symbol within them.

For example, This | is a example | line of text

I currently have some coding that will remove the pipe symbols from the text,

DATA: i_TABLE LIKE TABLE.
LOOP AT TABLE INTO i_TABLE.
REPLACE ALL OCCURRENCES OF '|'  IN i_TABLE-FIELD1
      WITH ''.
MODIFY TABLE FROM i_TABLE.

RESULT: This is a example line of text

What I need to do now is make an exception for a certain category that will only select the text from within the pipes (and remove the pipes)

DESIRED RESULT: is a example

I am not sure how to structure that code. can anyone give me some suggestions?

Best Regards,

Andrew

1 Accepted Solution
_Bruce_Robertson
Correct answer by
Level 10
Level 10

Hi Andrew,

You can use the split method to break the string into an array and then grab the second occurrence.

var textArray = "This | is a example | line of text".split("|");

var secondText = textArray[1];

If you need the remove the leading and trailing spaces, and all your users have Reader DC then you can use;

seondText.trim()

Regards

Bruce

View solution in original post

1 Reply
_Bruce_Robertson
Correct answer by
Level 10
Level 10

Hi Andrew,

You can use the split method to break the string into an array and then grab the second occurrence.

var textArray = "This | is a example | line of text".split("|");

var secondText = textArray[1];

If you need the remove the leading and trailing spaces, and all your users have Reader DC then you can use;

seondText.trim()

Regards

Bruce

View solution in original post