# utf8.codes

- **Ortam:** İstemci, Sunucu, Menü
- **İngilizce aslı:** https://wiki.facepunch.com/gmod/utf8.codes
- **Çeviri tarihi:** 2025-09-08

```lua
function utf8.codes( string string )
```

## Açıklama

Dizgedeki (string) her bir utf8 karakterinin hem konumunu hem de kod noktasını (codepoint) döndüren bir yineleyici (iterator) ([string.gmatch](https://gmod.tr/wiki/string.gmatch) gibi) döndürür. Herhangi bir geçersiz bayt dizisiyle karşılaşırsa bir hata verir.

## Argümanlar

1. [string](https://gmod.tr/wiki/string) **string**: Kodlarını alacağınız dizge.

## Döndürülen Değerler

1. [function](https://gmod.tr/wiki/function): Yineleyici (bir for döngüsünde kullanılmak üzere).

### Örnek

Fonksiyonun kullanımını gösterir.

```lua
for p, c in utf8.codes("( ͡° ͜ʖ ͡°)") do
    print(p,c)
end
```

**Çıktı:**

```lua
1    40
2    32
3    865
5    176
7    32
8    860
10    662
12    32
13    865
15    176
17    41
```

### Örnek

DLabel içinde metin animasyonu. [utf8.sub](https://gmod.tr/wiki/utf8.sub)'dan daha hızlı çalışır.

```lua
local str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Кириллица. Nam vel nunc quis nisl convallis ultrices. Suspendisse potenti. Quisque feugiat tincidunt aliquet. Curabitur id purus id nisi bibendum laoreet eu a lacus. Sed vel sollicitudin lorem."

local frame = vgui.Create("DFrame")
frame:SetSize(ScrW() * 0.4, ScrH() * 0.4)
frame:SetTitle("utf8.codes example")
frame:Center()

local label = vgui.Create("DLabel", frame)
label:Dock(TOP)
label:SetWrap(true)
label:SetFont("ChatFont")

label.symbolsToProcess = 0
label.Think = function(self)
    -- 'str' dizgesinden gelen karakterleri içerecek olan tablo
    local characters = {}
    -- Şu anda kaç karaktere sahip olduğumuz. Yeni karakterler eklemek için kullanılır
    local curLen = 0

    -- İşlememiz gereken sembol sayısı
    -- Mevcut Think() üzerindeki metnin uzunluğuyla eşleşecektir
    self.symbolsToProcess = self.symbolsToProcess + 1
    for _, code in utf8.codes(str) do
        if curLen >= self.symbolsToProcess then
            break
        end

        curLen = curLen + 1
        characters[curLen] = utf8.char(code)
    end

    self:SetText(table.concat(characters))
    -- Yeni satırlar olabileceğini varsayarak DLabel'ın yüksekliğini günceller
    self:SizeToContentsY(0)
end
```

**Çıktı:**

![utf8_codes_example.gif](https://gmod.tr/api/uploads/wiki/b419c603233cd332d574.gif)

- [GMod Wiki ana sayfası](https://gmod.tr/wiki)

---

[Tüm sunucular](https://gmod.tr/) · [GmodTR Launcher](https://gmod.tr/launcher) · [Rehber](https://gmod.tr/rehber) · [GMod Wiki](https://gmod.tr/wiki) · [GmodTR nedir?](https://gmod.tr/hakkinda) · [Sunucu ekle](https://gmod.tr/sunucu-ekle) · [Discord](https://discord.gg/gmodtr)

Kaynak: https://gmod.tr/wiki/utf8.codes
