Jump to content
Sign in to follow this  
JoeyHogan

Reducing a variable to a certain length

Recommended Posts

JoeyHogan

Hello all!

I'm writing a small program for the school district I work at. At the district, all computers are named in this format: bbb-rrrr-nn (b = building, r = room, n = number). So for example, one computer may be named AHS-B122-03.

The script I'm working on will need to read/write a specific file depending on what room it is in. I figured the easiest way to do this would be to cut off the last three characters of EnvGet("computername"). So that AHS-B122-03 would be cut down to just AHS-B122.

I'm trying to find a way to do this, but I'm not having much luck so far. Is there a way to cut a string down to a certain length? I can either go for just cutting it off at eight chars, or removing the last three, whichever is easiest.

Thanks!

Share this post


Link to post
Share on other sites
blakel

EnvGet("computername")

Why not use @ComputerName

Share this post


Link to post
Share on other sites
Malkey

Hello all!

I'm writing a small program for the school district I work at. At the district, all computers are named in this format: bbb-rrrr-nn (b = building, r = room, n = number). So for example, one computer may be named AHS-B122-03.

The script I'm working on will need to read/write a specific file depending on what room it is in. I figured the easiest way to do this would be to cut off the last three characters of EnvGet("computername"). So that AHS-B122-03 would be cut down to just AHS-B122.

I'm trying to find a way to do this, but I'm not having much luck so far. Is there a way to cut a string down to a certain length? I can either go for just cutting it off at eight chars, or removing the last three, whichever is easiest.

Thanks!

I like the versatility of regular expressions.

;
;$sStr = EnvGet("computername"); = @ComputerName
$sStr = "AHS-B122-03"
; \1 = building; \2 = room; \3 = number (if required)
$StrMod = StringRegExpReplace($sStr, "(.+)-(.+)-(.+)", "\1-\2")

MsgBox(0, "", $StrMod)
;

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.