[Question]
  [
**This question already has answers here**:
 
 
[Spell out the Revu'a](/questions/68901/spell-out-the-revua)
 (34 answers)
 
Closed 7 years ago.
The challenge is relatively simple, but will hopefully lead to some wonderfully creative answers. The task is to take a string as an input (via command line, function parameter etc.) and output/return a stringsploded version of it.
A stringsploded version of a string is its first letter followed by its first 2 letters, followed by its first 3 letters,... until you finally output the complete word.
You are guaranteed that the input will consist of printable ASCII characters and that the input will all be on one line (no new line characters).
Here are examples to clarify what stringsplosions are:
```
Input                 Output
==================================================================
"Code"       ---->   "CCoCodCode"
"name"       ---->   "nnanamname"
"harambe"    ---->   "hhaharharaharamharambharambe"
"sp aces?"   ---->   "sspsp sp asp acsp acesp acessp aces?"
"1234"       ---->   "1121231234"
"ss"         ---->   "sss"
```
This is code golf so shortest code wins + up votes for interesting uses of your respective language.
Good luck!
  
[Answer]
# [gs2](http://github.com/nooodl/gs2), 1 byte
# [`x`](http://gs2.tryitonline.net/#code=eA&input=SGVsbG8)
* `gs2` takes input from STDIN, and pushes it to the stack as a string.
* `x` is the **prefixes** built-in, returning a list of all prefixes of the argument, in ascending-length order.
* The resulting list of strings is implicitly printed one-by-one, without a delimiter, when the program terminates.
[Answer]
## [Jelly](https://github.com/DennisMitchell/jelly), 2 bytes
```
;\
```
Acculumate over concatenation gives all prefixes, which Jelly outputs to STDOUT without a delimiter. [Try it online!](http://jelly.tryitonline.net/#code=O1w&input=&args=ImFiY2RlMDEyMz8hICMi)
[Answer]
## [Retina](https://github.com/m-ender/retina), 4 bytes
```
.
$`
```
Expects the input to be terminated with a Windows-style `\r\n` newline (which seems fitting for a .NET-based programming language...).
This can be tested on [Regex Storm](http://regexstorm.net/tester?p=.&i=Code+Golf%0d%0a&r=%24%60) (which uses `\r\n` newlines). Click the "Context" tab for the result.
This is essentially the same as [Jordan's Ruby answer](https://codegolf.stackexchange.com/a/92536/8478): it replaces each character in the input (including the `\r` but not the `\n`) with all the characters that came before it. 
[Answer]
## Java 7, ~~81~~ 78 bytes
```
String g(String a){for(int i=a.length();i>0;)a=a.substring(0,--i)+a;return a;}
```
Straightforward method. Repeatedly prepends the shrinking prefix until it's done.
As a bonus, it should work for non-ASCII as well.
Sample:
```
Input:  ( ͡° ͜ʖ ͡°)
Output: (( ( ͡( ͡°( ͡° ( ͡° ͜( ͡° ͜ʖ( ͡° ͜ʖ ( ͡° ͜ʖ ͡( ͡° ͜ʖ ͡°( ͡° ͜ʖ ͡°)
```
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~5 4~~ 2 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
-2 bytes thanks to @Dennis
```
ḣJ
```
Test it at [**TryItOnline**](http://jelly.tryitonline.net/#code=4bijSg&input=&args=IkNvZGVHb2xmIC0gVGhlIEJlc3QgQmFuZyBGb3IgWW91ciBCeXRlIgo)  
Or all test cases, also at [**TryItOnline**](http://jelly.tryitonline.net/#code=4bijSgrDh-KCrFk&input=&args=IkNvZGUiLCJuYW1lIiwiaGFyYW1iZSIsInNwIGFjZXM_IiwiMTIzNCIsInNzIgo)
How?
```
ḣJ - Main link takes one argument, e.g. "Code"
 J    - range(length(input)), e.g. [1,2,3,4]
ḣ    - head, x[:y] (implicit vectorization), e.g. "CCoCodCode"
```
[Answer]
# [Brachylog](http://github.com/JCumin/Brachylog), ~~11~~ 5 bytes
```
:@[fc
```
[Try it online!](http://brachylog.tryitonline.net/#code=OkBbZmM&input=ImhhcmVtYmUi&args=Wg)
### Explanation
```
:@[f           Find all prefixes of the input
    c          Concatenate
```
[Answer]
# [05AB1E](http://github.com/Adriandmen/05AB1E), 3 bytes
```
.pJ
```
**Explanation**
```
.p   # get list of prefixes of input
  J  # join as string
```
[Try it online!](http://05ab1e.tryitonline.net/#code=LnBK&input=Q29kZQ)
[Answer]
# Ruby, 13 + 1 = 14 bytes
+1 byte for `-p` flag. Expects input on STDIN. Requires Windows-style line endings (`\r\n`).
```
gsub(/./){$`}
```
See it on eval.in (a few extra bytes since eval.in doesn't support command line flags): 
<https://eval.in/637093>
[Answer]
## Javascript (ES6), ~~28~~ 26 bytes
Recursively appends the shortened strings to the left of the final result:
```
f=s=>s&&f(s.slice(0,-1))+s
```
### Examples
```
var
f=s=>s&&f(s.slice(0,-1))+s
console.log(f("Code"));     //  -->   "CCoCodCode"
console.log(f("name"));     //  -->   "nnanamname"
console.log(f("harambe"));  //  -->   "hhaharharaharamharambharambe"
console.log(f("sp aces?")); //  -->   "sspsp sp asp acsp acesp acessp aces?"
console.log(f("1234"));     //  -->   "1121231234"
```
[Answer]
# [MATL](https://esolangs.org/wiki/MATL), ~~9~~ ~~8~~ 6 bytes
*2 bytes saved thanks to @Luis*
```
t&+Rf)
```
[**Try it Online!**](http://matl.tryitonline.net/#code=dCYrUmYp&input=J0NvZGUn)
**Explanation**
```
t       % Implicitly grab the input and duplicate
&+      % Broadcast and create a 2D matrix with all values > 0
R       % Grab the upper triangular portion (sets the lower triangular values to 0)
f       % Get the linear index for each value > 0
)       % Index into the original string (uses modular indexing)
        % Implicitly display the result
```
[Answer]
## JavaScript (ES6), 25 bytes
```
s=>s.replace(/./g,'$`$&')
```
[Answer]
# Perl, 10 bytes
Includes +1 for `-p`
Run with the input on STDIN:
```
splode.pl <<< "Hello"
```
`splode.pl`
```
#!/usr/bin/perl -p
s/./$`/sg
```
This depends on the input being terminated by a newline. This 11 byte version does not need a final newline:
```
#!/usr/bin/perl -lp
s/.?/$`/g
```
[Answer]
## [CJam](https://sourceforge.net/projects/cjam/), 8 bytes
Here's 4 separate ways to get 8 bytes
```
l_,),\f<
l{1$\+}*
l{+_}*co
Ll{+_}/;
```
Credits to @MartinEnder for the last one. [Online interpreter](http://cjam.aditsu.net/#code=l_%2C%29%2C%5Cf%3C&input=aabcde%2001!%40%23).
* `l_,),\f<` creates the range `[0 .. len(s)+1]` then uses `f<` to slice for each number, producing all prefixes.
* `l{1$\+}*` is a fold that duplicates the previous prefix and adds a char to it as it goes.
* `l{+_}*co` is a bit weird - `l{+_}*` is also a fold but it produces the wrong prefixes, skipping the first and doubling the last (e.g. `abcd` -> `ab/abc/abcd/abcd`, slashes for clarity). We then use `c` to turn the last string into just its first character and output it with `o`, to get the first prefix.
* `Ll{+_}/;` is a for-each loop that also duplicates the previous prefix and adds a char to it as it goes. We have an extra copy of the original string once the loop is over, which we pop with `;`.
[Answer]
## Haskell, ~~34 29 28~~ 26 bytes
```
reverse=<<scanl(flip(:))[]
```
[Answer]
# C, 49 bytes
```
i;f(char*n){for(i=0;i++<strlen(n);)write(1,n,i);}
```
[Try on Ideone](https://ideone.com/HjgvVU)
[Answer]
## [Jellyfish](http://github.com/iatorm/jellyfish), 5 bytes
```
P,\}I
```
[Try it online!](http://jellyfish.tryitonline.net/#code=UCxcfUk&input=Q29kZQ)
### Explanation
```
    I  # Read input.
  \}   # Get all prefixes.
 ,     # Flatten.
P      # Print.
```
[Answer]
# [V](http://github.com/DJMcMayhem/V), 8 bytes
```
òÄ$xhòíî
```
[Try it online!](http://v.tryitonline.net/#code=w7LDhCR4aMOyw63Drg&input=Y29kZQ)
[Answer]
# C#, ~~91~~ ~~87~~ ~~84~~ 83 bytes
```
void c(string n){var b="";for(int i=0;i<n.Length;)System.Console.Write(b+=n[i++]);}
```
Ungolfed:
```
void c(string n)
{
    var b = "";
    for (int i = 0; i < n.Length ; )
    {
        System.Console.Write(b+=n[i++]);
    }
}
```
Thank you Kevin Cruijssen.
[Answer]
# sed 41
```
h;:;G;s,.\n,\n,;h;s,\n.*,,;/./b;x;s,\n,,g
```
[Answer]
# [Sesos](https://github.com/DennisMitchell/sesos), 4 bytes
```
0000000: 8073ec 09                                         .s..
```
[Try it online!](http://sesos.tryitonline.net/#code=ICAgIGptcCwgcndkIDEsIGpuegogICAgZndkIDEKICAgIGptcCwgcHV0LCBmd2QgMSwgam56Cmpueg&input=Q29kZQ) Check *Debug* to see the generated SBIN code.
### Sesos assembly
The binary file above has been generated by assembling the following SASM code.
```
    jmp, rwd 1, jnz
    fwd 1
    jmp, put, fwd 1, jnz
jnz
```
[Answer]
# Python, ~~34~~ 28 bytes
Here's my rough attempt with a recursive solution:
```
f=lambda s:s and f(s[:-1])+s
```
Ungolfed:
```
def f(s):
    if s: return f(s[:-1]) + s
    return ''
```
Try it [here](https://ideone.com/dFBTgS)!
Thanks to @Dennis for -6 bytes.
[Answer]
# CJam, 11 bytes
```
q{(L\+:Lo}h
```
Explanation:
```
q                   get input
 {       }h         do while 
  (L                get 1st character and variable L (initialized with "")
    \+              swap and concatenate them
      :Lo           store result in L and print it
```
[Try it online](http://cjam.tryitonline.net/#code=cXsoTFwrOkxvfWg&input=Q29kZQ)
[Answer]
# [Dyalog APL](http://goo.gl/9KrKoM), 3 [bytes](http://meta.codegolf.stackexchange.com/a/9429/43319)
```
∊,\
```
`∊` flatten the
`,\` cumulative concatenation
[TryAPL online!](http://tryapl.org/?a=f%u2190%u220A%2C%5C%20%u22C4%20f%A8%27Code%27%20%27name%27%20%27harambe%27%20%27sp%20aces%3F%27%20%271234%27%20%27ss%27&run)
[Answer]
# Pyth, 3 bytes
```
s._
```
Explanation:
```
s   (s)um together 
 ._ all prefixes
```
[Answer]
# R, ~~60~~ 49 bytes
Not going to win any golf, but hopefully no shorter R answer is possible
```
cat(substring(s<-readline(),1,1:nchar(s)),sep="")
```
~~`paste0(substring(s<-readLines(,1),1,1:nchar(s)),collapse="")`~~
Thanks @MickyT
[Answer]
# Retina, 24 bytes
Well, I got destroyed by Martin, but here was my solution.
```
1m+`(.*).$
$1$.1$*¶$0
¶
```
[**Try it online**](http://retina.tryitonline.net/#code=MW0rYCguKikuJAokMSQuMSQqwrYkMArCtgo&input=Q29kZQ)
[Answer]
## PowerShell v2+, 43 bytes
```
param($n)-join(1..$n.length|%{$n[0..--$_]})
```
Takes input `$n`, loops from `1` to `$n.length`, each iteration slicing `$n` from `0` up to one less than the current number -- done because `.length` is 1-indexed, while array slicing is 0-indexed. Each iteration places characters on the pipeline, those are encapsulated in parens and `-join`ed together into one string. Output is implicit.
```
PS C:\Tools\Scripts\golfing> .\stringsplode-the-string.ps1 'PPCG'
PPPPPCPPCG
```
---
Alternatively, using Jordan's [Ruby submission](https://codegolf.stackexchange.com/a/92536/42963) as a basis, you can get to the following for **22 bytes**
```
$input-replace'.','$`'
```
This feels kinda cheaty, though, since you'd have to explicitly insert a newline into the string that you're piping in, or otherwise do a `Get-Content` or something out of a file that pulls the newlines with it. Valid, but not really common.
```
PS C:\Tools\Scripts\golfing> 'PPCG
' | .\stringsplode-the-string.ps1 $_
PPPPPCPPCG
```
[Answer]
# C ~~71~~ 67 Bytes
```
k;f(v){char*m,*n=v;while(*n++)for(k=0,m=v;k<n-v;k++)putchar(*m++);}
```
[Answer]
# Gema, 16 characters
```
?=@append{s;?}$s
```
Sample run:
```
bash-4.3$ echo -n 'sp aces?' | gema '?=@append{s;?}$s'
sspsp sp asp acsp acesp acessp aces?
```
[Answer]
# Python 3, 47 bytes
Thanks to @deustice
```
lambda s:''.join(s[:i]for i in range(len(s)+1))
```
[**Ideone it!**](https://ideone.com/jYx2c0)
]