Skip to main content
2 of 5
Forgot two test cases
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384

#Java 7, 189 bytes

String c(String s,char c){String r="";int x=0,i;for(String a:s.split("\\|")){for(i=0;i++<x;r+=" ");r+=a;x+=a.length();for(i=-1;i++<s.replace("|","").length()-x;r+=" ");r+=c+"\n";}return r;}

Ungolfed & test cases:

Try it here.

class M{
  static String c(String s, char c){
    String r = "";
    int x = 0,
        i;
    for(String a : s.split("\\|")){
      for(i = 0; i++ < x; r += " ");
      r += a;
      x += a.length();
      for(i = -1; i++ < s.replace("|", "").length() - x; r += " ");
      r += c + "\n";
    }
    return r;
  }

  public static void main(String[] a){
    System.out.println(c("a|bc|d|e|fgh|ij|k|l|mn|op", '#'));
    System.out.println(c("Hello|World", '/'));
    System.out.println(c("a|b|c|d|e|f|g", ','));
    System.out.println(c("abcdefg", ':'));
    System.out.println(c("4|8|15|16|23|42", '%'));
    System.out.println(c("E|ac|h s|ecti|on is| one c|haracte|r longer| than the| last!", '!'));
    System.out.println(c("This|Code|has||empty||sections", '@'));
  }
}

Output:

a                #
 bc              #
   d             #
    e            #
     fgh         #
        ij       #
          k      #
           l     #
            mn   #
              op #

Hello      /
     World /

a       ,
 b      ,
  c     ,
   d    ,
    e   ,
     f  ,
      g ,

abcdefg :

4          %
 8         %
  15       %
    16     %
      23   %
        42 %

E                                                   !
 ac                                                 !
   h s                                              !
      ecti                                          !
          on is                                     !
                one c                               !
                     haracte                        !
                            r longer                !
                                     than the       !
                                              last! !

This                     @
    Code                 @
        has              @
                         @
           empty         @
                         @
                sections @
Kevin Cruijssen
  • 131.4k
  • 13
  • 144
  • 384