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!

  2. LOOKING FOR A VERSION OF SKRIPT?

    You can always check out our Wiki for downloads and any other information about Skript!

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

Way to cut/sub a string? This should be simple...

Discussion in 'Skript' started by mccrafter1212, Jul 22, 2017.

Thread Status:
Not open for further replies.
  1. mccrafter1212

    mccrafter1212 Member

    Joined:
    Jul 16, 2017
    Messages:
    11
    Likes Received:
    0
    Let's assume I have this code:

    Code (Skript):
    1. set {specialString} to "This is a special string"
    How can I get the last word in that string and set that to a variable?
     
  2. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,173
    Likes Received:
    199
    There is some methode. For easy way:

    Code (Skript):
    1. set {_S::*} to {specialString} split at " "
    2. set {_s} to size of {_S::*}
    3. send "This is last word: %{_s::%{_s}%}%"
     
  3. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,173
    Likes Received:
    199
    Or, use this:
    Code (Skript):
    1. set {_last-word} to subtext of {specialString} from (last index of " " in {specialString} + 1) to {specialString}'s length
     
  4. ShaneBee

    Moderator Resource Staff Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,173
    Likes Received:
    199
    If using this method its much easier just to do
    Code (Skript):
    1. set {_s} to last element out of split {_string} at " "
     
Thread Status:
Not open for further replies.
Loading...