1. 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!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'Snippets' started by Dovias, Feb 19, 2020.

  1. Dovias

    Dovias New Member

    Joined:
    Dec 8, 2019
    Messages:
    6
    Likes Received:
    0
    [​IMG]

    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.

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

    Code (Text):
    1. expression split %string% [by] every %number% character[s]:
    2.     return type: texts
    3.     get:
    4.         set {_string::*} to expression-1 split at ""
    5.         remove "" from {_string::*}
    6.         loop {_string::*}:
    7.             add 1 to {_a}
    8.             if {_a} is not expression-2:
    9.                 add loop-value-1 to {_c::*}
    10.             else:
    11.                 add loop-value-1 to {_c::*}
    12.                 set {_string} to concat {_c::*}
    13.                 add {_string} to {_s::*}
    14.                 delete {_c::*}
    15.                 set {_a} to 0
    16.         set {_string} to concat {_s::*}
    17.         if length of expression-1 is not length of {_string}:
    18.             set {_string} to concat {_c::*}
    19.             add {_string} to {_s::*}
    20.         return {_s::*}

    Usage:
    Code (Text):
    1. command /split:
    2.     trigger:
    3.         set {_split::*} to split "12345678987654321" by every 3 characters
    4.         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.
    --- Double Post Merged, Feb 19, 2020, Original Post Date: Feb 19, 2020 ---
    Blue's solution to this. Credits to him.

    Code (Text):
    1. plural expression %string% split [every] %integer% char[acter][s]:
    2.   return type: strings
    3.   get:
    4.     set {_i} to 0
    5.     while {_i} < length of expr-1:
    6.       add subtext of expr-1 from indices {_i} and {_i}+expr-2 to {_r::*}
    7.       add expr-2 to {_i}
    8.     return {_r::*}
     

Share This Page

Loading...