Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ MUSHclient ➜ VBscript ➜ Manipulating strings for fun and profit!

Manipulating strings for fun and profit!

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Neva   USA  (117 posts)  Bio
Date Mon 20 Jan 2003 10:41 PM (UTC)
Message
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?
Top

Posted by Shadowfyr   USA  (1,792 posts)  Bio
Date Reply #1 on Mon 20 Jan 2003 11:39 PM (UTC)
Message
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. ;)
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #2 on Tue 21 Jan 2003 03:59 AM (UTC)
Message
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.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Shadowfyr   USA  (1,792 posts)  Bio
Date Reply #3 on Tue 21 Jan 2003 08:14 AM (UTC)
Message
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. ;)
Top

Posted by Poromenos   Greece  (1,037 posts)  Bio
Date Reply #4 on Tue 21 Jan 2003 09:36 AM (UTC)
Message
Well, it's not that big, just 6 :p

Vidi, Vici, Veni.
http://porocrom.poromenos.org/ Read it!
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #5 on Tue 21 Jan 2003 10:12 AM (UTC)

Amended on Tue 21 Jan 2003 10:13 AM (UTC) by Nick Gammon

Message
And the difference between &h100 and 100? Gets larger doesn't it? ;-P

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Neva   USA  (117 posts)  Bio
Date Reply #6 on Tue 21 Jan 2003 01:12 PM (UTC)
Message
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. :)
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


28,080 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.