VBScript: Strings, You Can`t Function without Them - LTrim That Hair You Hippie!
(Page 2 of 6 )
Let's face it, we all could use a little trimming. On our left side, and well, on our right side too. I mean, if you lopped off like fifty pounds from my left side, I would turn into one of those bopper weeble bags that you punch and it just bounces right back up.
Strings in VBScript can sometimes have the same problem. If you want to get rid of those extra spaces on the left side of a string, then LTrim is your friend. Your skinny, good-looking friend you love to hate. That bastard.
<html>
<body>
<script type="text/vbscript">
dim s
s=" We are the Space Invaders! We have come to...well...invade your space! "
document.write(LTrim(s)) & "<br />"
</script>
</body>
</html>
This deletes the spaces on the left hand side of the string, resulting in:
We are the Space Invaders! We have come to...well...invade your space!
RTrim...Like LTrim But on the Other Side!
As the title says, RTrim() is the same as LTrim, only on the other side. There isn't really much else to say about it, so here it is in code:
<html>
<body>
<script type="text/vbscript">
dim s
s=" We are the Space Invaders! We have come to...well...invade your space! "
document.write(RTrim(s)) & document.write("Look out we've collided with some text because you ate our spaces!")
</script>
</body>
</html>
This gives us the result of:
Look out we've collided with some text because you ate our spaces! We are the Space Invaders! We have come to...well...invade your space!
Next: Trim()ming the Fat >>
More Windows Scripting Articles
More By James Payne