[Question]
  [
### Introduction
For this example, let's take the string `Hello, World!` and the array `[3, 2, 3]`. To find the substring chain, we go through the following process:
The first number of the array is `3`, so we get the substring `[0 - 3]`, which is `Hel`. After that, we remove the first `3` characters from the initial string, which leaves us with `lo, World!`.
The second number of the array is `2`, so we get the substring `[0 - 2]` from our new string, which gives us `lo`. The leftover string becomes `, World!`.
The last number is a `3`, which gives us `, W`. The **substring chain** is all of the substrings combined, which gives us:
```
['Hel', 'lo', ', W']
```
For a more visual example:
```
[3, 2, 3], 'Hello, World!'
3 -> Hel
2 ->    lo
3 ->      , W
```
### The task
Given **a *non-empty* string** and **a *non-empty* array** only consisting of **positive integers** (`> 0`), output the **substring chain**. You may assume that the sum of all integers in the array does not exceed the length of the string.
You can also assume that the strings will never contain any newlines.
### Test cases
```
Input: abcdefghijk, [2, 1, 3]
Output: ['ab', 'c', 'def']
Input: Code Golf, [4, 1]
Output: ['Code', ' ']
Input: Ayyy, [3]
Output: ['Ayy']
Input: lexicographically, [2, 2, 2, 7, 4]
Output: ['le', 'xi', 'co', 'graphic', 'ally']
```
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the submission with the smallest number of bytes wins!
  
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), 1 byte
```
£
```
This is the substring(0,N) command.  
Applied on a list this works repeatedly on the remainder on the string.
[Try it online!](http://05ab1e.tryitonline.net/#code=wqM&input=WzIsIDIsIDIsIDcsIDRdCmxleGljb2dyYXBoaWNhbGx5)
[Answer]
## Python 2, 42 bytes
```
s,a=input()
for n in a:print s[:n];s=s[n:]
```
Sometimes you just do it the boring way.
[Answer]
# [Brachylog](http://github.com/JCumin/Brachylog), ~~20~~ 13 bytes
```
h@[~c.:la~t?,
```
[Try it online!](http://brachylog.tryitonline.net/#code=aEBbfmMuOmxhfnQ_LA&input=WyJhYmNkZWZnaGlqayI6WzI6MTozXV0&args=Wg)
This is extremely inefficient and times out on TIO for the last test case.
### Explanation
```
Input = [String, List of integers]
h@[            Take a prefix of the string
   ~c.         Take a possible list of strings which when concatenated results in that prefix
      :la      Take the lengths of each element of that list
         ~t?,  This list of lengths is equal to the list of integers of the Input
```
### A slightly more efficient version, 15 bytes
[```
t:{~l}a.,?h@[~c
```](http://brachylog.tryitonline.net/#code=dDp7fmx9YS4sP2hAW35j&input=WyJsZXhpY29ncmFwaGljYWxseSI6WzI6MjoyOjc6NF1d&args=Wg)
[Answer]
# Python 3, 45 bytes
```
f=lambda s,a:f(s[a[0]:print(s[:a.pop(0)])],a)
```
This prints one substring per line and terminates with an error when **a** is exhausted.
Test it on [repl.it](https://repl.it/Ddza).
[Answer]
# Python, ~~52~~, 46 bytes
```
f=lambda a,s:a and[s[:a[0]]]+f(a[1:],s[a[0]:])
```
A recursive lambda function.
*Thanks to Dennis for shaving off 6 bytes!*
[Answer]
# [Jelly](http://github.com/DennisMitchell/jelly), 6 bytes
```
Jx$ĠịY
```
[Try it online!](http://jelly.tryitonline.net/#code=SngkxKDhu4tZ&input=&args=WzMsIDIsIDNd+J0hlbGxvLCBXb3JsZCEn)
```
        The implicit working value is the first argument.
Jx$     Given a list L, repeat (x) an element of [1..len(n)] (J)
        as many times as the corresponding value in L.
   Ġ    Group indices by values. This turns [1, 1, 1, 2, 2, 3, 3]
        into [[1, 2, 3], [4, 5], [6, 7]].
    ị   Index into the second argument.
     Y  Join by newlines.
```
[Answer]
## Haskell, 34 bytes
```
s#(a:b)=take a s:drop a s#b
_#_=[]
```
Usage example: `"lexicographically" # [2,2,2,7,4]` -> `["le","xi","co","graphic","ally"]`
Simple recursion.
Or the boring **29 bytes** solution via built-in:
```
import Data.Lists
splitPlaces
```
[Answer]
# Ruby, 26 bytes
```
->w,a{a.map{|n|w.shift n}}
```
Strings are represented as arrays of characters.
[Answer]
## PowerShell v2+, 46 bytes
```
param($a,$b)$b|%{-join$a[$i..($i+=$_-1)];$i++}
```
Takes input string `$a` and array `$b`, loops over `$b`. Each iteration, does an array slice of `$a` based on `$i` (defaults to `$null`, or `0`) and the current number. Needs to do the `-1` and `$i++` because strings in PowerShell are zero-indexed.
### Examples
(The output here is space-separated, because that's the default stringification method for arrays)
```
PS C:\Tools\Scripts\golfing> @('abcdefghijk',@(2,1,3)),@('Code Golf',@(4,1)),@('Ayyy',@(3)),@('lexicographically',@(2,2,2,7,4))|%{""+$_[0]+" -> "+(.\substring-chainification.ps1 $_[0] $_[1])}
abcdefghijk -> ab c def
Code Golf -> Code  
Ayyy -> Ayy
lexicographically -> le xi co graphic ally
```
[Answer]
# Perl, 28 bytes
Includes +1 for `-n`
Run with the input string on STDIN followed by each number on a separate line:
```
(echo "Hello, World!"; echo 3; echo 2; echo 3) | perl -nE 'say for/(??{"."x<>||"^"})/g'
```
Just the code:
```
say for/(??{"."x<>||"^"})/g
```
The 23 bytes version without `||"^"` also sort of works, but prints spurious trailing newlines
`"^"` can be replaced by `$_` if the string does not contain regex meta characters
[Answer]
# [MATL](http://github.com/lmendo/MATL), 8 bytes
```
ys:)1bY{
```
[Try it online!](http://matl.tryitonline.net/#code=eXM6KTFiWXs&input=WzIsIDEsIDNdCidhYmNkZWZnaGlqaycK)
### Explanation
```
y    % Implicitly take the two inputs: numerical array, string. Duplicate the array
s    % Sum of the array, say n
:    % Range from 1 to n
)    % Take first n characters of the string
1    % Push 1
b    % Bubble up the original copy of the string to the top
Y{   % Split into pieces of lengths given by the numerical array. The pieces are 
     % stored in a cell array, which is implicitly displayed, one cell per line
     
```
[Answer]
## JavaScript (ES6), ~~39~~ ~~38~~ 35 bytes
Saved 3 bytes thanks to ETHproductions:
```
s=>a=>a.map(v=>s.slice(t,t+=v),t=0)
```
Example: 
```
//Definition
f=
s=>a=>a.map(v=>s.slice(t,t+=v),t=0)
//Call
f('lexicographically')([2, 2, 2, 7, 4]);
//Output
Array [ "le", "xi", "co", "graphic", "ally" ]
```
---
Previous solution:  
38 bytes thanks to Huntro:
```
s=>a=>a.map(v=>s.substr(t,v,t+=v),t=0)
```
39 bytes:
```
(s,a)=>a.map(v=>s.substr(t,v,t+=v),t=0)
```
[Answer]
## Batch, 74 bytes
```
@set/ps=
@for %%i in (%*)do @call echo %%s:~0,%%i%%&call set s=%%s:~%%i%%
```
I'm beating C? This can't be right! Takes the string on STDIN and the array as command-line arguments.
[Answer]
# Java, 119 Bytes
```
String[] substringChainification(String s, int[] i) {
    String[] r = new String[i.length];
    int j = 0, f = 0;
    for (int t : i)
        r[j++] = s.substring(f, f += t);
    return r;
}
```
**Golfed:**
```
String[]s(String s,int[]i){String[]r=new String[i.length];int j=0,f=0;for(int t:i)r[j++]=s.substring(f,f+=t);return r;}
```
I modified Roman Gräf's answer(<https://codegolf.stackexchange.com/a/93992/59935>), but i don't have enough rep to comment.
I changed the loop implementation and instead of setting the source string to another substring in every iteration, i just change the indices with which i get the substring.
[Answer]
## Pyke, 10 bytes
```
FQR<
Ki?>Q
```
[Try it here!](http://pyke.catbus.co.uk/?code=FQR%3C%0AKi%3F%3EQ&input=abcdefghijk%0A%5B2%2C+1%2C+3%5D)
[Answer]
# sed (82 + 2 for -rn) 84
```
s,^,\n,;:l;N;s,\n\n,\n,;:
s,^([^\n]*)\n(.)([^\n]*\n)1,\1\2\n\3,
t;P;s,^[^\n]*,,;tl
```
The first line of input is the string. Then each line after that is the size of a substring in [unary](http://meta.codegolf.stackexchange.com/questions/5343/can-numeric-input-output-be-in-unary?answertab=votes#tab-top).
Example:
```
$ cat test.txt:
lexicographically
11
11
11
1111111
1111
$ cat hold | sed -rnf sed.txt
le
xi
co
graphic
ally
```
[Answer]
## [CJam](http://sourceforge.net/projects/cjam/), 11 bytes
```
lq~{/(ns}/;
```
[Try it online!](http://cjam.tryitonline.net/#code=bHF-ey8obnN9Lzs&input=bGV4aWNvZ3JhcGhpY2FsbHkKWzIgMiAyIDddCg)
### Explanation
```
l    e# Read input string.
q~   e# Read array of lengths and eval.
{    e# For each length...
  /  e#   Split the string into chunks of the given size.
  (  e#   Pull off the first chunk.
  n  e#   Print with linefeed.
  s  e#   Flatten the remaining chunks into a single string again.
}/
;    e# Discard any remainder of the input string.
```
[Answer]
# C, 81 bytes
```
i,j;f(s,l,k)char*s;int*l;{for(i=j=0;i<k;){write(1,s+j,l[i]);puts("");j+=l[i++];}}
```
Because `write()` output is not buffered any online compiler will have a hard time outputting this.
**test.c**:
```
i,j;f(s,l,k)char*s;int*l;{for(i=j=0;i<k;){write(1,s+j,l[i]);puts("");j+=l[i++];}}
main(){
    int l[]={3,2,3};
    f("Hello, World!",l,3);
    int ll[]={2,1,3};
    f("abcdefghijk",ll,3);
    int lll[]={4,1};
    f("Code Golf",lll,2);
    int llll[]={3};
    f("Ayyy",llll,1);
    int lllll[]={2,2,2,7,4};
    f("lexicographically",lllll,5);
}
```
Output without piping:
```
Hel
lo
, W
ab
c
def
Code
 
Ayy
le
xi
co
graphic
ally
```
[Answer]
# PHP, 98 Bytes
```
<?php
$b=$argv[1];foreach(explode(',',$argv[2])as$a){echo(substr($b,0,$a).' ');$b=substr($b,$a);}
```
**Usage:**
  
```
php chainification.php lexicographically 2,2,2,7,4
```
  
**Output:**
  
```
le xi co graphic ally
```
  
There's probably a better solution with PHP.
[Answer]
# PHP, 82 Bytes
```
<?php for($s=$argv[++$i],$j=-1;$n=$argv[++$i];){for(;$n--;)echo$s[++$j];echo"
";}
```
Takes input as a string and then a list of numbers, output is separated by new lines. e.g.
```
php chainify.php lexicographically 2 2 2 7 4
```
If you're one of those people able to use $argv with -r you can save the 6 bytes used for the opening tag.
[Answer]
# PHP, 63 Bytes
```
<?foreach($_GET[a]as$p){echo" ".substr($_GET[s],$s,$p);$s+=$p;}
```
Output as Array 85 Bytes
```
<?foreach($_GET["a"]as$p){$o[]=substr($_GET["s"],$s,$p);$s+=$p;}echo json_encode($o);
```
[Answer]
# Rebol, 38 bytes
```
func[s b][map-each n b[take/part s n]]
```
[Answer]
# Pyth, 7 bytes
```
PcwsM._
```
Takes input separated by newline, with the string unescaped and coming after the array.
[Try it Online!](http://pyth.herokuapp.com/?code=PcwsM._&input=%5B3%2C2%2C3%5D%0AHello%2C+World%21&debug=0)
Explanation:
```
     ._  Get all prefixes of Q
   sM    Map sum across each of these prefixes (to get the total indices)
 cw      Split the string at these locations
P        Remove the last "remainder" of the string
```
[Answer]
# Octave / MATLAB, 31 bytes
```
@(s,a)mat2cell(s(1:sum(a)),1,a)
```
This is an anonymous function with inputs `s`: string; `a`: numerical array.
[Try it at Ideone](http://ideone.com/PL4hZs).
### Explanation
This is a port of my MATL answer.
```
s(1:sum(a))        % Take first n characters of string s, where n is the sum of array a
mat2cell(...,1,a)  % Split into pieces of lengths given by a and store in a cell array
```
[Answer]
# Java 142 bytes
```
public static String[]substringChain(String s,int[]i){
  String[]r=new String[i.length];
  for(int j=-1;++j<i.length;){
    r[j]=s.substring(0,i[j]);
    s=s.substring(i[j]);
  }
  return b;
}
```
Golfed:
```
String[]s(String s,int[]i){String[]r=new String[i.length];for(int j=-1;++j<i.length;){r[j]=s.substring(0,i[j]);s=s.substring(i[j]);}return b;}
```
[Answer]
# Awk, 36 characters
```
{FIELDWIDTHS=$0;OFS=RS;getline}$1=$1
```
Sample run:
```
bash-4.3$ awk '{FIELDWIDTHS=$0;OFS=RS;getline}$1=$1' <<< $'3 2 3\nHello, World!'
Hel
lo
, W
```
In real life I would use it like this, just no idea how to calculate its score:
```
bash-4.3$ awk -vFIELDWIDTHS='3 2 3' -vOFS='\n' '$1=$1' <<< 'Hello, World!'
Hel
lo
, W
```
[Answer]
# [Dyalog APL](http://goo.gl/9KrKoM) 16.0, 15 [characters](http://meta.codegolf.stackexchange.com/a/9429/43319) (non-competing); 15.0, 17 [bytes](http://meta.codegolf.stackexchange.com/a/9429/43319)
### 16.0 solution
```
{⍵⊆⍨(⍴⍵)↑⍺/+\⍺}
```
Dyalog APL 16.0 adds APL2's [partition](http://help.dyalog.com/15.0/Content/Language/Primitive%20Functions/Partition.htm) primitive, `⊂`, with the glyph `⊆`.
### 15.0 solution:
```
{(-⍺)↑¨(+\⍺)↑¨⊂⍵}
```
[TryAPL online!](http://tryapl.org/?a=3%202%203%20%7B%28-%u237A%29%u2191%A8%28+%5C%u237A%29%u2191%A8%u2282%u2375%7D%20%27Hello%2C%20World%21%27&run)
[Answer]
## GNU sed, 55 + 2(rn flags) = 57 bytes
```
1H;1d;G;:;s=.(\n.*)\n(.)=\1\2\n=;t;s=.==;P;s=[^\n]*==;h
```
**[Try it online!](http://sed.tryitonline.net/#code=MUg7MWQ7Rzs6O3M9Lihcbi4qKVxuKC4pPVwxXDJcbj07dDtzPS49PTtQO3M9W15cbl0qPT07aA&input=YWJjZGVmZ2hpamsKMDAKMAowMDAK&args=LXJu)** (thanks to @Dennis for adding sed)
**Explanation:** The input string should be on the first line and the numbers, [in unary](https://codegolf.meta.stackexchange.com/questions/5343/can-numeric-input-output-be-in-unary?answertab=votes#tab-top "consensus"), on separate lines after that. A new line is read implicitly at the start of a cycle, running the script each time.
```
1H;1d                       # once: append string to hold space and start new cycle
                            #Initially, the hold space contains an useful '\n'.
G                           # append hold space to pattern space. The pattern space
                            #format will be: 'UNARY\n\nSTRING'.
:;s=.(\n.*)\n(.)=\1\2\n=;t  # iteratively remove a char from the string, as many
                            #times as unary chars, and store it on 2nd pattern line
s=.==;P                     # remove '\n', then print the new top line
s=[^\n]*==;h                # delete up to '\n' and update hold space
```
**Test run:** using a here-document with EOF as the end marker
```
sed -rnf program.sed << EOF
> abcdefghijk
> 00
> 0
> 000
> EOF
```
**Output:**
```
ab
c
def
```
[Answer]
## Ruby, 28 bytes
```
->a,w{a.map{|e|w.slice!0,e}}
```
In case arguments are an array of positive integers and one string.
[Answer]
# Vimscript, ~~79~~ 78 bytes
not very pretty, I'm sure it can be improved... 
Takes a vim buffer, then call `echom string(A([2,3]))` to see the output 
```
fu A(l)
let r=[]
for i in a:l
exe "norm d".i."l"
let r+=[@"]
endfo
retu r
endf
```
I actually thought of cheating and outputing the *string* `["abc", "def"]`... But I resisted :P
Explanation: Delete (puts in default register) each array items amounts of characters and adds it to the array `r`... A boring answer indeed. 
]