Super Contributor.. Giulio Soleni Super Contributor..
Super Contributor..

split a string into pieces of N characters


I need to split an input sting into pieces of N chars.

Since I did not find any predefined operation to accomplish this task I thought I could use a simple "No Operation" step and arrange the results with a sleep script, but I cannot find any example to start.


The perl code should be pretty simple... something like the following:


$string = $inString; # inString should be the 1st step input
$partLength = $inPart; # inPart should be the 2nd step input
my @parts = $string =~ /.{1,$partLength}/sg;
print @parts;

Anyone may help me in setting up a Sleep or Rhino scriplet to define this step?


Or maybe there's a better way in OO to manage strings and split a long string in several pieces of fixed lenght.


Thank you,


Labels (1)
4 Replies
Absent Member.. ntt00015 Absent Member..
Absent Member..

Re: split a string into pieces of N characters


Try this one. Hope this helps.


Try to write scriptlet. Just add a "Do Nothing" operation to your flow.
3 inputs : 1. sourceString, 2.delimiter, 3. substringLength
2 outputs : 1. substringList, 2. listCount

myString= scriptletContext.get("sourceString"); //input 1
myDelimiter=scriptletContext.get("delimiter"); //input 2
mySubStrLen=scriptletContext.get("substringLength"); //input 3

mySubStrArray=new Array();
forCount = Math.ceil( myString.length / mySubStrLen);
subDummy = myString.slice(arrPosStart,arrPosEnd);
mySubStrArray[i]= subDummy;



scriptletContext.put("substringList",myList); //output 1
scriptletContext.put("listCount",forCount); //output 2

After that you can use a "List Item Grabber" operation in a loop.
input parameters:
list<= substringList (output of no operation)
delimiter<= delimiter (input of no operation)
index<= the number of cell in the array (from loop operation result)

Absent Member.. koby_el Absent Member..
Absent Member..

Re: split a string into pieces of N characters

You can play with the result of a "Display" operation, or a "Do Nothing" operation. (I did it with that)

But you'll have to relay on some characters or something like that....

meetlesli Absent Member.
Absent Member.

Re: split a string into pieces of N characters

is there any library for string split

Absent Member.. Steve_Drummond Absent Member..
Absent Member..

Re: split a string into pieces of N characters

Is there a HPOO Operation that splits a string? No.


Is there a library for String split? Yes.


str.split([separator][, limit])

Specifies the character(s) to use for separating the string. The separator is treated as a string or a regular expression. If separator is omitted, the array returned contains one element consisting of the entire string. If separator is an empty string, str is converted to an array of characters.
Integer specifying a limit on the number of splits to be found. The split method still splits on every match of separator, but it truncates the returned array to at most limit elements.


The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.