JoeyHogan Posted May 2, 2009 Share Posted May 2, 2009 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! Link to comment Share on other sites More sharing options...
blakel Posted May 2, 2009 Share Posted May 2, 2009 StringLeft() Link to comment Share on other sites More sharing options...
blakel Posted May 2, 2009 Share Posted May 2, 2009 EnvGet("computername")Why not use @ComputerName Link to comment Share on other sites More sharing options...
Malkey Posted May 2, 2009 Share Posted May 2, 2009 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) ; Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now