Split text on right most space before limit is reached

Split text on right most space before limit is reached
Use to split text on several lines in receiving document, eg edifact LIN-IMD-C273 has several 7008 text element

//    -----------------------------
//    Peter Lykkegaard, 22 mar 2019
//    -----------------------------
//    Split long note on right most space before limit is reached
//    TODO! Check parameters if they are of valid type/content
//
//    Name: splitNoteBySpace
//    Description: Method to split a given string by latest space before length limit
//    Parameters
//        input$, alphanumerical / String which needs to be split
//        max$, alphanumerical / Max characters on each line
//    Output, alphanumeric / array / Array of strings to return
 
local lvOutput$[];

#importJavaStart
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
#importJavaEnd
 
#javastart

    String input = _StrVar_PINPUT.getString();
    int max = (int)_NumVar_PMAX.getNum();
    int len = input.length();
    
    String regex = "(.{1," + max + "})(?:\\s|$)";
 
    Pattern pattern = Pattern.compile(regex, Pattern.MULTILINE);
    Matcher matcher = pattern.matcher(input);
    
    _StrVar_LVOUTPUT.getJuVar(0, 2).setString(input);

    if (len > max)
    {
        int idx = 0;     // Entries in output   
        while (matcher.find()) {
            for (int i = 1; i <= matcher.groupCount(); i++) {
                _StrVar_LVOUTPUT.getJuVar(idx, 2).setString(matcher.group(i).toString());
            }
            idx++;
        }
    }
#javaEnd
     
exitProc(lvOutput$);

 

getCurrentYear

An utility to retrieve current year

This is a procedure to use in Seeburger BIC Mapping Designer

/*  -----------------------------
    Peter Lykkegaard, 25 apr 2023
    -----------------------------
    procedure getUUID
  
    Parameters:
        None
    Output
        String
    Get ramdom UUID
    ----------------------------- */
 
#importJavaStart
    import java.util.UUID;
#importJavaEnd

local 
    lvOutput$;

#javastart
    _StrVar_LVOUTPUT.setString(UUID.randomUUID().toString());
#javaend

exitProc(lvOutput$);

 

unescapeHTML

An utility to decode or unescape HTML characters in XML (EDI) documents

This is a procedure to use in Seeburger BIC Mapping Designer
It will extend your library for string handling

/*  -----------------------------
    Peter Lykkegaard, 25 apr 2023
    -----------------------------
    procedure unescapeHTML

    Parameters:
        Source / String, alphanumeric
    Output
        String, alphanumericString

    Adapted from How to Unescape HTML in Java using Plain Java
    https://howtodoinjava.com/java/string/unescape-html-to-string/
    ----------------------------- */

local lvOutput$;

#importJavaStart
    import java.util.HashMap;
#importJavaEnd

// Save source in case changes are not needed
copy pSource$ to lvOutput$;

// Check for any ampersand / & character
if (containsSubstring(pSource$, "&") != 0)

    if (containsSubstring(pSource$, "&") != 0)
        // HTML decode ampersand / &
        copy replaceAll(pSource$, "&", "&") to pSource$;
    endif
    
#javastart

    int i, j;

    boolean continueLoop;
    int skip = 0;

    HashMap<String, String> htmlEntities = new HashMap<String, String>();

    htmlEntities.put("<", "<");
    htmlEntities.put(">", ">");
    htmlEntities.put("&", "&");
    htmlEntities.put(""", "\"");
    htmlEntities.put(" ", " ");
    htmlEntities.put("©", "\u00a9");
    htmlEntities.put("®", "\u00ae");
    htmlEntities.put("€", "\u20a0");

    htmlEntities.put("Å", "Å");
    htmlEntities.put("Æ", "Æ");
    htmlEntities.put("Ø", "Ø");

    htmlEntities.put("å", "å");
    htmlEntities.put("æ", "æ");
    htmlEntities.put("ø", "ø");

    String source = _StrVar_PSOURCE.getString();

    do {
        continueLoop = false;
        i = source.indexOf("&", skip);
        if (i > -1) {
            j = source.indexOf(";", i);
            if (j > i) {
                String entityToLookFor = source.substring(i, j + 1);
                String value = (String) htmlEntities.get(entityToLookFor);
                if (value != null) {
                    source = source.substring(0, i) + value + source.substring(j + 1);
                    continueLoop = true;
                } else if (value == null) {
                skip = i + 1;
            continueLoop = true;
          }
        }
      }
    } while (continueLoop);

    _StrVar_LVOUTPUT.setString(source);

#javaend

endif
   
exitProc(lvOutput$);



Split string

An utility to split a string based on an character 

A procedure to use in Seeburger BIC Mapping Designer
It will extend your library for string handling

//    -----------------------------
//    Peter Lykkegaard, 22 mar 2019
//    -----------------------------
//    Split string into its sub components based input characters

//    TODO! Check paramteters if they are of valid type/content
//
//    Name: splitString
//    Description: 
//    Parameters
//        input$, alphanumerical / String which needs to be split
//        criteria$, alphanumerical / Character to split
//    Output, alphanumeric / array / Array of strings to return

local output$[];

#javastart

    final String input = _StrVar_INPUT.getString();
    final String criteria = _StrVar_CRITERIA.getString();

    String[] data;

    if ((criteria == "-") || (criteria == "+") || (criteria == "|"))
    {
        data = input.split("\\" + criteria + "|\\*|\\/");
    }
    else
    {
        data = input.split(criteria, 0);
    }
    
    int idx = 0;

    for (int i = 0; i < data.length; i++) 
    { 
        _StrVar_OUTPUT.getJuVar(idx, 2).setString(data[i]);
        idx++;
    }

#javaEnd
    
exitProc(output$);

 

Remove White Space

An utility to remove all white space from a given string

A procedure to use in Seeburger BIC Mapping Designer
It will extend your library for string handling

// ------------
/* --------------------------------------------
    removeWhiteSpace

        Parameters
            input$
        returns
            string

   Removes all white space from the given string 
   -------------------------------------------- */

local output$;

#javaStart
    String output = _StrVar_INPUT.getString();
    output = output.replaceAll("\\s+", "");
    _StrVar_OUTPUT.setString(output);
#javaEnd

exitProc(output$);