Changing an IP-Address

Hello Guys.
I wanted to write a script, which changes some ip-address values. I wanted to delete every char after the “/” in an ip-address.
As expample turning 192.168.1.100/24 to 192.168.1.100

I wrote the following code but can not get any output.

        :local Pstring 192.168.1.100/24
        :local cP;
        :local slash /;

            :for i from=0 to=([:len $Pstring] - 1) do={ 
                :local char [:pick $Pstring $i];
                :local oneAfter [:pick $Pstring [$i +1]];
                :local twoAfter [:pick $Pstring [$i +2]];
                :if ($char = $slash) do={

                    :set $char  "";
                    :set $oneAfter "";
                    :set $twoAfter "";
                }
                :set $cP ($cP . $char)
            }
            :put $cp;

What am I doing wrong?
Any help would be appreciated:)

Something like that?

{
:local ipAdd 192.168.1.100/24
:set ipAdd [:toip [:pick $ipAdd 0 [:find $ipAdd "/"]]]
:put $ipAdd
}
Output ==> 192.168.1.100

BR.

@karaYusuf You do it on wrong way, and the topic title is completely inadequate.

{
:local lcidr 192.168.1.100/24
:local lip   [:pick $lcidr 0 [:find $lcidr "/"]]
:local lsub  [:pick $lcidr ([:find $lcidr "/"] + 1) [:len $lcidr]]

:put "$lcidr = $lip / $lsub"
}

Exactly what I needed. Thank you very much :slight_smile:

I am sorry.

{
:local lcidr 192.168.1.100/24
:local lip [:pick $lcidr 0 [:find $lcidr "/"]]
:local lsub [:pick $lcidr ([:find $lcidr "/"] + 1) [:len $lcidr]]

:put "$lcidr = $lip / $lsub"
}

>

So which one should I use?
The one you wrote me or the other one?

Both do the same, the second (my) do not uselessly use :toip‡ and containing also one example for extract subnet, if is needed,
and also the variable names are more adequate…

‡: depend on the rest of the script…