number part of string to variable

  • 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 community!

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

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

mrxqware

Member
Apr 19, 2017
17
0
0
Hi there,

I've got a region named building12
I would like to get the integer from the string and save it in a variable.

Code:
on region enter:
   message "Entering %region%."
    if "%region%" contains "building":
       set {_tempstring} to region

The output of %region% is:
Code:
building12 in world world

I would like to save the number in the string in a variable.

So when a player enters a region named: building14

then the variable should be set to: 14

What's the best way to do that?

Hope you can help me.
Many thanks in advance.
 
code_language.skript:
on region enter:
    message "Entering %region%."
    if "%region%" contains "building":
        set {_region::*} to "%region%" split at " "
        replace all "building" in {_region::1} with ""
        set {_tempstring} to "%{_region::1}%" parsed as an integer
# {_tempstring} is your output
 
hi @HiiqhFive! Many thanks for helping me out! Looks great and compact. I will try it out.
 
Last edited by a moderator:
code_language.skript:
on region enter:
    message "Entering %region%."
    if "%region%" contains "building":
        set {_region::*} to "%region%" split at " "
        replace all "building" in {_region::1} with ""
        set {_tempstring} to "%{_region::1}%" parsed as an integer
# {_tempstring} is your output
You could just do:
code_language.skript:
set {_num} to first element of (split "%region%" by " ") parsed as "building%int%"
 
Status
Not open for further replies.