一般字符串函数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一般字符串函数相关的知识,希望对你有一定的参考价值。

A small collection of the most wanted string-functions in ASP / VB.
  1. ' Count the chars in a string
  2. ' =========
  3. response.write(len("1234567"))
  4. ' Output: 7
  5. ' =========
  6.  
  7. ' Edit date
  8. ' =========
  9. DateAdd(Interval, Amount, yourDate)
  10. DateAdd("ww", 2, now)
  11. DateAdd("ww", -2, now)
  12.  
  13. ' Value Description
  14. ' ============================
  15. ' yyyy Year
  16. ' q Quarter
  17. ' m Month
  18. ' y Day of the year
  19. ' d Day
  20. ' w Weekday
  21. ' ww Week of a year
  22. ' h Hour
  23. ' n Minute
  24. ' s Second
  25. ' =========
  26.  
  27. ' Search in string
  28. ' =========
  29. foo = "12.34"
  30. response.write(instr(foo, "."))
  31. ' Output: 3
  32. ' =========
  33.  
  34. ' Cut string
  35. ' =========
  36. response.write(left("1234567", 3))
  37. ' Output: 123
  38. response.write(right("1234567", 3))
  39. ' Output: 567
  40. response.write(mid("1234567", 3, 2))
  41. ' Output: 34
  42. response.write(mid("1234567", 3))
  43. ' Output: 567
  44. ' =========
  45.  
  46. ' String into float
  47. ' =========
  48. String = "12,26"
  49. Float = CDbl(String)
  50. Result = Float + 7.74
  51. ' =========
  52.  
  53. ' String into int
  54. ' =========
  55. String = "12,26"
  56. Int = CInt(String)
  57. Result = Int + 7.74
  58. ' =========
  59.  
  60. ' Split string
  61. ' =========
  62. foo = "My-Name"
  63. bar = split(foo, "-")
  64. response.write(bar(0) & " " & bar(1))
  65. ' Output: My Name
  66. ' =========
  67.  
  68. ' Replace' =========
  69. foo = "My-Name"
  70. response.write(replace(foo,"-"," "))
  71. ' Output: My Name
  72. ' =========

以上是关于一般字符串函数的主要内容,如果未能解决你的问题,请参考以下文章

21个常用代码片段

10个JavaScript代码片段,使你更加容易前端开发。

10个JavaScript代码片段,使你更加容易前端开发。

VSCode自定义代码片段——声明函数

VSCode自定义代码片段8——声明函数

解决方案电影标题中缺少代码的片段,完成挑战更多[关闭]