feat: 添加字符串工具函数(split, trim, substring, replace, contains, upper, lower, starts_with, ends_with)及相关测试用例
This commit is contained in:
@@ -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"))
|
||||
|
||||
Reference in New Issue
Block a user