---
title: split – ฟังก์ชันแยกข้อความจากตัวคั่น
url: https://www.thepexcel.com/functions/n8n/string-functions/split-n8n/
type: function-explainer
program: n8n
syntax: "split(text, separator)"
date: 2025-12-16
updated: 2025-12-17
scores:
  popularity: 8
  difficulty: 3
  usefulness: 8
---

# split – ฟังก์ชันแยกข้อความจากตัวคั่น

> แยกข้อความจากตัวคั่น

## คำอธิบาย

split แยกข้อความออกเป็นอาร์เรย์ตามตัวคั่นที่ระบุ ฟังก์ชันนี้มีประโยชน์ในการแยกชื่อ สกัดข้อมูล หรือแปลงข้อความยาวเป็นรายการ

## Syntax

```excel
split(text, separator)
```

**Variant**

```excel
$json.names.split(',')
```

แยกชื่อที่คั่นด้วยเครื่องหมายจุลภาค

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| text | Yes | string |  | ข้อความที่ต้องการแยก |
| separator | Yes | string |  | ตัวคั่นสำหรับการแยก |

## เคสการใช้งาน

### แยกรายชื่อ

แยกชื่อหลายๆ คนที่คั่นด้วยเครื่องหมายจุลภาค

_เหมาะกับ:_ name-splitting

### แยก URL

แยก URL path เป็นส่วนๆ

_เหมาะกับ:_ url-parsing

## ตัวอย่าง

### 1. ตัวอย่างที่ 1: แยกข้อความด้วยเครื่องหมายจุลภาค

```excel
{{ split('John,Jane,Bob', ',') }}
```

**ผลลัพธ์:** `[John, Jane, Bob]`

แยกชื่อเป็นอาร์เรย์

### 2. ตัวอย่างที่ 2: แยก URL path

```excel
{{ split('/api/v1/users', '/') }}
```

**ผลลัพธ์:** `["", api, v1, users]`

แยก URL path เป็นส่วนๆ

### 3. ตัวอย่างที่ 3: แยก CSV

```excel
{{ $json.csvLine.split(';') }}
```

**ผลลัพธ์:** `[field1, field2, field3]`

แยกข้อมูล CSV คั่นด้วยเซมิโคลอน

## หมายเหตุเพิ่มเติม

⚠️ ฟังก์ชัน split() สร้างอาร์เรย์ สมาชิกว่างถ้าตัวคั่นติดกัน ใช้ join() เพื่อทำกลับเป็นข้อความ

## คำถามที่พบบ่อย

**Q: split() จะสร้างสมาชิกว่างถ้าตัวคั่นติดกันหรือไม่?**

ใช่ split() จะสร้างสมาชิกว่างในอาร์เรย์ ใช้ filter() เพื่อลบออก

**Q: split() จะรับ regex pattern ได้หรือ?**

ได้ split() รับ regex pattern สำหรับการแยกที่ซับซ้อนขึ้น

**Q: ใช้ split() เมื่อไหร่ในการทำงาน?**

ใช้เมื่อต้องแยกข้อความตามตัวคั่น เช่น CSV, รายชื่อ, หรือ URL

## ฟังก์ชันที่เกี่ยวข้อง

- [join – แปลงอาร์เรย์เป็นข้อความด้วยตัวคั่น](https://www.thepexcel.com/functions/n8n/array-functions/join-n8n/)
- [slice – ดึงส่วนของข้อความหรืออาร์เรย์](https://www.thepexcel.com/functions/n8n/array-functions/slice-n8n/)
- [trim – ลบ whitespace หน้าและหลังข้อความ](https://www.thepexcel.com/functions/n8n/string-functions/trim-n8n/)
- [extractUrl – ฟังก์ชันดึง URL จากข้อความ](https://www.thepexcel.com/functions/n8n/string-functions/extract-url-n8n/)

## แหล่งข้อมูลเพิ่มเติม

- [n8n Expressions: split Function](https://docs.n8n.io/code/expressions/) _(documentation)_

---

_Source: [https://www.thepexcel.com/functions/n8n/string-functions/split-n8n/](https://www.thepexcel.com/functions/n8n/string-functions/split-n8n/)_
