string_methods.ion 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. echo '# ANCHOR: basename'
  2. echo $basename("/parent/filename.ext")
  3. echo '# ANCHOR_END: basename'
  4. echo '# ANCHOR: extension'
  5. echo $extension("/parent/filename.ext")
  6. echo '# ANCHOR_END: extension'
  7. echo '# ANCHOR: filename'
  8. echo $filename("/parent/filename.ext")
  9. echo '# ANCHOR_END: filename'
  10. echo '# ANCHOR: join'
  11. let array = [1 2 3 4 5]
  12. echo $join(array)
  13. echo $join(array ", ")
  14. echo '# ANCHOR_END: join'
  15. echo '# ANCHOR: find'
  16. echo $find("FOOBAR" "OB")
  17. echo $find("FOOBAR" "ob")
  18. echo '# ANCHOR_END: find'
  19. echo '# ANCHOR: len'
  20. echo $len("foobar")
  21. echo $len("❤️")
  22. echo $len([one two three four])
  23. echo '# ANCHOR_END: len'
  24. echo '# ANCHOR: len_bytes'
  25. echo $len_bytes("foobar")
  26. echo $len_bytes("❤️")
  27. echo '# ANCHOR_END: len_bytes'
  28. echo '# ANCHOR: parent'
  29. echo $parent("/root/parent/filename.ext")
  30. echo '# ANCHOR_END: parent'
  31. echo '# ANCHOR: repeat'
  32. echo $repeat("abc, " 3)
  33. echo '# ANCHOR_END: repeat'
  34. echo '# ANCHOR: replace'
  35. let input = "one two one two"
  36. echo $replace(input one 1)
  37. echo $replace($replace(input one 1) two 2)
  38. echo '# ANCHOR_END: replace'
  39. echo '# ANCHOR: replacen'
  40. let input = "one two one two"
  41. echo $replacen(input "one" "three" 1)
  42. echo $replacen(input "two" "three" 2)
  43. echo '# ANCHOR_END: replacen'
  44. echo '# ANCHOR: regex_replace'
  45. echo $regex_replace("bob" "^b" "B")
  46. echo $regex_replace("bob" 'b$' "B")
  47. echo '# ANCHOR_END: regex_replace'
  48. echo '# ANCHOR: reverse'
  49. echo $reverse("foobar")
  50. echo '# ANCHOR_END: reverse'
  51. echo '# ANCHOR: to_lowercase'
  52. echo $to_lowercase("FOOBAR")
  53. echo '# ANCHOR_END: to_lowercase'
  54. echo '# ANCHOR: to_uppercase'
  55. echo $to_uppercase("foobar")
  56. echo '# ANCHOR_END: to_uppercase'
  57. echo '# ANCHOR: escape'
  58. let line = " Mary had\ta little \n\t lamb\t"
  59. echo $escape($line)
  60. echo '# ANCHOR_END: escape'
  61. echo '# ANCHOR: unescape'
  62. let line = " Mary had\ta little \n\t lamb\t"
  63. echo $unescape($line)
  64. echo '# ANCHOR_END: unescape'
  65. echo '# ANCHOR: or'
  66. echo $or($unknown_variable "Fallback")
  67. let var = 42
  68. echo $or($var "Not displayed")
  69. echo '# ANCHOR_END: or'