Skip to content

String Operations

Text manipulation: case conversion, split, pad, slugify, template, and more.

11 modules

ModuleDescription
Chữ thườngChuyển chuỗi thành chữ thường
Pad StringPad a string to a specified length
Thay thế chuỗiThay thế các lần xuất hiện của chuỗi con trong chuỗi
Đảo ngược chuỗiĐảo ngược các ký tự trong chuỗi
SlugifyConvert text to URL-friendly slug
Tách chuỗiTách chuỗi thành mảng sử dụng dấu phân cách
TemplateRender a template with variable substitution
Kiểu tiêu đềChuyển chuỗi thành kiểu tiêu đề
Cắt khoảng trắngXóa khoảng trắng ở hai đầu chuỗi
Truncate StringTruncate a string to a maximum length
Chữ hoaChuyển chuỗi thành chữ hoa

Modules

Chữ thường

string.lowercase

Chuyển chuỗi thành chữ thường

Parameters:

NameTypeRequiredDefaultDescription
textstringYes-The text string to process

Output:

FieldTypeDescription
resultstringChuỗi đã chuyển thành chữ thường
originalstringChuỗi đã chuyển thành chữ thường
statusstringChuỗi đã chuyển thành chữ thường

Pad String

string.pad

Pad a string to a specified length

Parameters:

NameTypeRequiredDefaultDescription
textstringYes-Text to pad
lengthnumberYes-Text to pad
pad_charstringNoTarget length
positionstringNoendCharacter to pad with

Output:

FieldTypeDescription
resultstringPadded string
originalstringPadded string
addednumberPadded string

Thay thế chuỗi

string.replace

Thay thế các lần xuất hiện của chuỗi con trong chuỗi

Parameters:

NameTypeRequiredDefaultDescription
textstringYes-The text string to process
searchstringYes-The substring to search for in the input text
replacestringYes-Text to replace matches with (leave empty to remove matches)

Output:

FieldTypeDescription
resultstringChuỗi đã được thay thế
originalstringChuỗi đã được thay thế
searchstringChuỗi đã được thay thế
replacestringChuỗi đầu vào gốc
statusstringChuỗi tìm kiếm đã được thay thế

Đảo ngược chuỗi

string.reverse

Đảo ngược các ký tự trong chuỗi

Parameters:

NameTypeRequiredDefaultDescription
textstringYes-The text string to process

Output:

FieldTypeDescription
resultstringChuỗi đã đảo ngược
originalstringChuỗi đã đảo ngược
lengthnumberChuỗi đã đảo ngược

Slugify

string.slugify

Convert text to URL-friendly slug

Parameters:

NameTypeRequiredDefaultDescription
textstringYes-Text to slugify
separatorstringNo-Text to slugify
lowercasebooleanNoTrueWord separator
max_lengthnumberNo0Convert to lowercase

Output:

FieldTypeDescription
resultstringMaximum slug length (0 = unlimited)
originalstringURL-friendly slug

Tách chuỗi

string.split

Tách chuỗi thành mảng sử dụng dấu phân cách

Parameters:

NameTypeRequiredDefaultDescription
textstringYes-The text string to process
delimiterselect (,, ;, , , `
, , -, _`)NoCharacter(s) to split the string on

Output:

FieldTypeDescription
partsarrayMảng các phần chuỗi đã tách
resultarrayMảng các phần chuỗi đã tách
lengthnumberMảng các phần chuỗi đã tách
originalstringAlias cho parts - mảng các phần chuỗi đã tách
delimiterstringSố phần sau khi tách
statusstringChuỗi đầu vào gốc

Template

string.template

Render a template with variable substitution

Parameters:

NameTypeRequiredDefaultDescription
templatestringYes-Template string with {{variable}} placeholders
variablesobjectYes-Variables to substitute
missing_valuestringNo-Value for undefined variables
preserve_missingbooleanNoFalseValue for undefined variables

Output:

FieldTypeDescription
resultstringKeep placeholder if variable is missing
replacednumberRendered template
missingarrayRendered template

Kiểu tiêu đề

string.titlecase

Chuyển chuỗi thành kiểu tiêu đề

Parameters:

NameTypeRequiredDefaultDescription
textstringYes-The text string to process

Output:

FieldTypeDescription
resultstringChuỗi đã chuyển thành kiểu tiêu đề

Example: Convert to title case

yaml
text: hello world from flyto

Example: Format name

yaml
text: john doe

Cắt khoảng trắng

string.trim

Xóa khoảng trắng ở hai đầu chuỗi

Parameters:

NameTypeRequiredDefaultDescription
textstringYes-The text string to process

Output:

FieldTypeDescription
resultstringChuỗi đã cắt bỏ khoảng trắng
originalstringChuỗi đã cắt bỏ khoảng trắng
statusstringChuỗi đã cắt bỏ khoảng trắng

Truncate String

string.truncate

Truncate a string to a maximum length

Parameters:

NameTypeRequiredDefaultDescription
textstringYes-Text to truncate
lengthnumberYes-Text to truncate
suffixstringNo...Maximum length
word_boundarybooleanNoFalseText to append if truncated

Output:

FieldTypeDescription
resultstringBreak at word boundary
originalstringTruncated string
truncatedbooleanTruncated string
removednumberOriginal string

Chữ hoa

string.uppercase

Chuyển chuỗi thành chữ hoa

Parameters:

NameTypeRequiredDefaultDescription
textstringYes-The text string to process

Output:

FieldTypeDescription
resultstringChuỗi đã chuyển thành chữ hoa
originalstringChuỗi đã chuyển thành chữ hoa
statusstringChuỗi đã chuyển thành chữ hoa

Released under the Apache 2.0 License.