Manipulating strings for fun and profit!

Posted by Neva on Mon 20 Jan 2003 10:41 PM — 7 posts, 29,597 views.

USA #0
Or something. :)

Basically, this is what gets me on VBScript, because I don't find any of the documentation I've found particularly comprehensible, so... is there a resource somewhere on how to manipulate strings? Say I have a string like, oh...

0000000072000000007200000000080000000008

I want to get, for example, the second '72' out of there, by pulling the second set of ten characters, then trimming the leading zeros.

How do I go about doing that?
USA #1
Try to find an old book on programming DOS basic? lol MS docs are designed as near as I can tell to be incomprehensible and hard to find anything in. This is assuming that the help file is even available. I recently started working on smething that I thought I would use an ActiveX control from and discovered that while the dll needed to use it was there the hlp and cnt files are only available for it if you previously installed Word or Excel. :P

In any case the stuff for manipulation of strings are:

left(string, length)
right(string, length)
and
mid(string, start, length)

In your case something like:

Num = right(mid(YourString, 11, 10), 2) would return the last two digits of the second set of numbers. ;)
Australia Forum Administrator #2
I gather you might want to trim leading zeroes from what might be a 10-digit number? Do what Shadowfyr suggested, except pull out 10 digits, do a CInt to convert to a number, then CStr to convert back to a string. That should get rid of the zeroes.
USA #3
Yes. Nick's idea is a better one. However.. when I see a mess of leading zeroes like that I tend to think of Hex values. I the case of those you need to do something like Cint("&h" & mid(string,start,10)). If you don't add the &h then VBScript won't see a number, but will instead interpret anything containing the letters "ABCDEF" as a string value.

However.. If these are just normal numbers that happen to have been slapped together, then do what Nick suggests, since obviously there is a big difference between &h10 and 10. ;)
Greece #4
Well, it's not that big, just 6 :p
Australia Forum Administrator #5
And the difference between &h100 and 100? Gets larger doesn't it? ;-P
Amended on Tue 21 Jan 2003 10:13 AM by Nick Gammon
USA #6
I'm not working in hex, anyway. Don't know the first thing *about* hex. The game I'm scripting for is designed to be used mostly with a proprietary frontend, and so it sends these long strings of numbers to inform the frontend of things it needs to update in the display. :)

Now, the complicated part is going to be the section that involves a string of binary that stands for a variety of things converted to decimal... but as that feature isn't high on my list and I'm low on screen real estate anyway, that can wait. :)