feat: 添加字符串工具函数(split, trim, substring, replace, contains, upper, lower, starts_with, ends_with)及相关测试用例

This commit is contained in:
0264408
2026-06-16 19:44:54 +08:00
parent bf705069a5
commit 8e49df8062
4 changed files with 402 additions and 0 deletions
+27
View File
@@ -180,3 +180,30 @@ fn is_palindrome(s) {
print("is_palindrome('radar'):", is_palindrome("radar"))
print("is_palindrome('hello'):", is_palindrome("hello"))
// ============================================================================
// 7. 字符串工具(split / trim / substring / replace
// ============================================================================
print("=== string utils ===")
let csv = "Alice,Bob,Carol,Dave"
let parts = split(csv, ",")
print("split CSV:", parts)
print("names count:", len(parts))
let padded = " hello "
print("trim:", "'" + trim(padded) + "'")
print("substring('hello', 1, 3):", substring("hello", 1, 3))
let template = "Hello, NAME!"
let greeting = replace(template, "NAME", "Aster")
print("replace:", greeting)
print("contains('hello', 'ell'):", contains("hello", "ell"))
print("upper:", upper("hello"))
print("lower:", lower("HELLO"))
print("starts_with('hello', 'he'):", starts_with("hello", "he"))
print("ends_with('hello', 'lo'):", ends_with("hello", "lo"))