Sign in to follow this  
Followers 0
gcue

truncating variable value

13 posts in this topic

in dos we are able to truncate the value of a variable as such

%fecha:~24,9%

is there a way to do that in autoit?

id like to truncate

bguser\abcds

where abcds can be anywhere between 2-10 characters

hope this make sense

Share this post


Link to post
Share on other sites



$x = StringSplit("bguser\absgdghgfhfgjf","\")
$x[1] ;-> "bguser"
$x[2] ; -> "absgdghgfhfgjf"


*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Share this post


Link to post
Share on other sites

ok on the right track.. but when i did this, it user[2] = "absgdghgfhfgjf"

and NOT what the value truly is

i want it to grab anything after the "\" regardless of what the characters are

did i forget something?

thanks

Share this post


Link to post
Share on other sites

ok on the right track.. but when i did this, it user[2] = "absgdghgfhfgjf"

and NOT what the value truly is

i want it to grab anything after the "\" regardless of what the characters are

did i forget something?

thanks

That IS the text after the slash.

Share this post


Link to post
Share on other sites

thats the text in the code.. but not the text from the registry values im pulling from different remote machines.

Share this post


Link to post
Share on other sites

Tell me this doesn't work:

$x = StringSplit("bguser\absgdghgfhfgjf","\")
MsgBox(0,"",$x[2])

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

thats the text in the code.. but not the text from the registry values im pulling from different remote machines.

Can you post an example string?

Share this post


Link to post
Share on other sites

sorry maybe i shoulda mentioned this before..im pulling registry values from remote machines (so the values are always changing depending on what machine im querying)

$user = RegRead("\\" & $assets[$x] & "\HKEY_LOCAL_MACHINE\SOFTWARE\Altiris\Altiris Agent\Inventory", "PrimaryUser")

THEN i try to get just the username (wout the domain) as the value. the following returns "asdfasdf" only

$user = StringSplit("BGUSER\asdfasdf", "\")

MsgBox(0,"",$user[2])

sorry bout that.

Share this post


Link to post
Share on other sites

Not so hard.

MsgBox(0,"",$user[1])

Share this post


Link to post
Share on other sites

ok here are the exact details/steps:

$user = RegRead("\\" & $assets[$x] & "\HKEY_LOCAL_MACHINE\SOFTWARE\Altiris\Altiris Agent\Inventory", "PrimaryUser")

this outputs different values for different machines:

BGUSER\AFKDD

BGUSER\KJDKF

BGUSER\DKFJDJF

TGUSER\DKFJ

CGUSER\DFLKLD

etc...

i want to seperate both sides of the "\" for each entry no matter what the domain is or the account name. i would imagine i only need to specify the seperator and maybe use some type of wildcard?

hope i was clearer this time =)

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

???

$user = RegRead("\\" & $assets[$x] & "\HKEY_LOCAL_MACHINE\SOFTWARE\Altiris\Altiris Agent\Inventory", "PrimaryUser")
$array=StringSplit($user,"\")
MsgBox(0,"",$array[1]) ; This is the left side of the \ sign
MsgBox(0,"",$array[2]) ; This is the right side of the \ sign
Edited by monoceres

Broken link? PM me and I'll send you the file!

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

weird it works when you do it on one machine.. which makes sense. but not when u do it on an array of machines.

error " array variable has incorrect number of subscripts or subscript dimension range exceeded."

still looking..

thanks.

Edited by gcue

Share this post


Link to post
Share on other sites

weird it works when you do it on one machine.. which makes sense. but not when u do it on an array of machines.

error " array variable has incorrect number of subscripts or subscript dimension range exceeded."

still looking..

thanks.

Gotta debug man.

$assets[4] = ["Computer1","Computer2","Computer4","Computer4"]

For $X = 0 to Ubound($assets) - 1
    ConsoleWrite("Computer name: " & $assets[$x] & @CRLF)
    $user = RegRead("\\" & $assets[$x] & "\HKEY_LOCAL_MACHINE\SOFTWARE\Altiris\Altiris Agent\Inventory", "PrimaryUser")
    
    If NOT @ERROR Then
        $array=StringSplit($user,"\")
        ConsoleWrite("Username: " & $array[1] & @CRLF) ; This is the left side of the \ sign
        ConsoleWrite("Domain: " & $array[2] & @CRLF) ; This is the right side of the \ sign     
    Else
        ConsoleWrite("RegRead FAIL" & @CRLF)
    EndIf
    ConsoleWrite(@CRLF)
Next

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  
Followers 0