[expression] Split text by every "x" characters.

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!


New Member
Dec 8, 2019

Want to split text by every "x" characters, but cant find an expression which does this?
No problem, just use this freshly made expression by me!. Add this to new .sk file or at the top of your skript of choice. You could use this without the skript-mirror, but i know there's a lot of people who are new to skript, so i tried to make it as simple as possible.

  • Skript version that's compatible with skript-mirror (preferably 4.1)
  • skript-mirror (preferably 2.0.0-SNAPSHOT)

expression split %string% [by] every %number% character[s]:
    return type: texts
        set {_string::*} to expression-1 split at ""
        remove "" from {_string::*}
        loop {_string::*}:
            add 1 to {_a}
            if {_a} is not expression-2:
                add loop-value-1 to {_c::*}
                add loop-value-1 to {_c::*}
                set {_string} to concat {_c::*}
                add {_string} to {_s::*}
                delete {_c::*}
                set {_a} to 0
        set {_string} to concat {_s::*}
        if length of expression-1 is not length of {_string}:
            set {_string} to concat {_c::*}
            add {_string} to {_s::*}
        return {_s::*}

command /split:
        set {_split::*} to split "12345678987654321" by every 3 characters
        broadcast "Result: %{_split::*}%"

Where can I use this?
For splitting large texts, in to multiple lines. For example if you have an item in a gui in which has dynamic player, server info, and that information could be too big to display in one line, so you just decide how long you want your lore to be and split it in to multiple lines using this expression.
[doublepost=1582140118,1582139837][/doublepost]Blue's solution to this. Credits to him.

plural expression %string% split [every] %integer% char[acter][s]:
  return type: strings
    set {_i} to 0
    while {_i} < length of expr-1:
      add subtext of expr-1 from indices {_i} and {_i}+expr-2 to {_r::*}
      add expr-2 to {_i}
    return {_r::*}