Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Button handy
blanktrue
color#0052CC
nameSend Feedback
linkhttps://docs.google.com/forms/d/e/1FAIpQLScmToBe3vynAlb5fdKwCGxYqnTbDc66sIBgeecG2BuFDuHc7g/viewform?entry.2002826954=Using+the+split%28%29+Function+-+491002050
widthauto

Many support requests come from users who want to do some kind of text parsing. One of the most effective (and easiest!) ways of parsing scripts is by using the split() routinefunction.

Splitting a Multiline Text Custom Field

Let's say you want to get the value of the third line a multiline text field. At first, this may seem difficult but not if we use the split() routinefunction. For example:

Code Block
string [] textLines = split(#{textFieldMultiLine}, "\\u000A");
string thirdLine = textLines[2];

As you can see by the above code that we can split up the lines by telling the SIL interpreter to look for the line feed unicode (\u000A). Since our escape character is embedded inline, we use two escape characters. 

...

https://en.wikipedia.org/wiki/List_of_Unicode_characters

String Concatenation

Let's say you wanted to join all lines of our hypothetical multiline text field. You can either loop through all the elements and append each element together, or you can cheat and use the replace() routinefunction.

Code Block
string [] textLines = split(#{textFieldMultiLine}, "\\u000A");
string allTogether = replace(textLines, "|", "");

All this does is replace pipe separators found in an array with an empty string. The same thing can be accomplished by using the join() routinefunction:

Code Block
string [] textLines = split(#{textFieldMultiLine}, "\\u000A");
string allTogether = join(textLines, " ");

Splitting a Table in Confluence

A user was kind enough to post an example of how he split values in a table in Confluence.

Code Block
number pageId = getPage("DEMO", "table example");
string [] tabletext = split(pageId.content, "table>");
string [] tables;
 
 
int i;
int j=0;
for(i=0; i<size(tabletext); i++){
    if(contains(tabletext[i],"<tbody>")){
        tables[j] = "<table>" + tabletext[i] + "table>";
        j++;
    }
}

As you can see, using the split() routine function can be used to parse text in surprising (yet effective) ways.

Additional Help

Need help implementing this script? Talk to me directly to me by clicking on the bot on this page. 

Filter by label (Content by label)
showLabelsfalse
max5
spacescom.atlassian.confluence.content.render.xhtml.model.resource.identifiers.SpaceResourceIdentifier@135a7
sortmodified
showSpacefalse
reversetrue
typepage
cqllabel = "kb-how-to-article" and type = "page" and space = "PKB"
labelskb-how-to-article
Page Properties
hiddentrue

Related issues

We've encountered an issue exporting this macro. Please try exporting this page again later.