string.Explode

  table string.Explode( string separator, string str, boolean withpattern = false )

Açıklama

Verilen ayırıcıyı bulduğu her yerde bir iplik bölüyor.

Fonksiyonu string. Split Bu fonksiyonun bir takma adıdır, ancak function doesn desen kullanmayı desteklemez.

Görelim. string. Implode Bu fonksiyonun ters çalışması için.

Argümanlar

1. dizgin Ayırıcı
Dizgi bu dizinin bulunduğu her yerde ayrılır.
2. dizgin str
Bölmek için iplik.
3. Boolean Şablonla. = yanlış
Eğer ayırıcınız bir ise bunu doğru olarak ayarlayın. Şablon.

Geri dönüşler

1. sıralı Tablodizgin>
Bir sayısal sıralama tablosu olarak patlamış bir dize.

Örnek

Bir cümleyi içindeki kelimelerin tablosuna ayırır.

local sentence = "hello there my name is Player1" local words = string.Explode( " ", sentence ) PrintTable( words )
Çıkış:
1 = hello 2 = there 3 = my 4 = name 5 = is 6 = Player1

Örnek

Bir oyuncunun söylediği kelimeleri sıralamak için Explode kullanır.

hook.Add( "PlayerSay", "GiveHealth", function( ply, text ) local playerInput = string.Explode( " ", text ) if ( playerInput[1] == "!givehealth" ) then if ( tonumber( playerInput[2] ) ) then ply:SetHealth( tonumber( playerInput[2] ) ) print( ply:Nick() .. " set their health to " .. playerInput[2] ) end end end)
Çıkış:
Player1 set their health to 100.

Örnek

Bir cümleyi her basamakta bir tabloya ayırır.

local sentence = "Separated 4 every digit like 1 and 2" local words = string.Explode("%d", sentence, true) PrintTable( words )
Çıkış:
1 = Separated 2 = every digit like 3 = and 4 =

Tüm sunucular · GmodTR Launcher · Rehber · GMod Wiki · GmodTR nedir? · Sunucu ekle · Discord