General string-functions


/ Published in: ASP
Save to your folder(s)

A small collection of the most wanted string-functions in ASP / VB.


Copy this code and paste it in your HTML
  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. ' =========

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.