---
title: substring – ฟังก์ชันดึงส่วนของข้อความตามตำแหน่ง
url: https://www.thepexcel.com/functions/n8n/string-functions/substring-n8n/
type: function-explainer
program: n8n
syntax: "substring(text, start, length)"
date: 2025-12-16
updated: 2025-12-17
scores:
  popularity: 7
  difficulty: 3
  usefulness: 7
---

# substring – ฟังก์ชันดึงส่วนของข้อความตามตำแหน่ง

> ดึงส่วนของข้อความตามตำแหน่ง

## คำอธิบาย

substring ดึงส่วนของข้อความตามตำแหน่ง ฟังก์ชันนี้มีประโยชน์ในการตัดสินข้อความ สกัดส่วน หรือการจัดการข้อมูลบางส่วน คล้ายกับ slice แต่ใช้เฉพาะข้อความ

## Syntax

```excel
substring(text, start, length)
```

**Variant**

```excel
$json.name.substring(0, 3)
```

ดึง 3 ตัวอักษรแรก

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| text | Yes | string |  | ข้อความที่ต้องการดึง |
| start | Yes | number |  | ตำแหน่งเริ่มต้น |
| length | No | number | ไม่ระบุ (ดึงจาก start ถึงสิ้นสุด) | จำนวนตัวอักษรที่ต้องการ |

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

### ดึงรหัสส่วน

ดึง 3 ตัวอักษรแรกจากรหัส

_เหมาะกับ:_ code-extraction

## ตัวอย่าง

### 1. ตัวอย่างที่ 1: ดึง 3 ตัวอักษร

```excel
{{ substring('ABCDEF', 0, 3) }}
```

**ผลลัพธ์:** `ABC`

ดึง 3 ตัวอักษรจากตำแหน่ง 0

### 2. ตัวอย่างที่ 2: ดึงส่วนกลาง

```excel
{{ substring($json.code, 2, 4) }}
```

**ผลลัพธ์:** `CDEF`

ดึง 4 ตัวอักษรจากตำแหน่ง 2

### 3. ตัวอย่างที่ 3: แปลงรูป

```excel
{{ substring('2024-12-13', 0, 4) }}
```

**ผลลัพธ์:** `2024`

ดึงส่วนปีจากวันที่

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

⚠️ ฟังก์ชัน substring() ใช้เฉพาะข้อความ ใช้ร่วมกับ slice() สำหรับอาร์เรย์

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

**Q: substring() และ slice() ต่างกันอย่างไร?**

substring() ใช้ (start, length) slice() ใช้ (start, end) เท่านั้น

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

ใช้เมื่อต้องดึงส่วนของข้อความตามตำแหน่งและยาว

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

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

---

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