Jump to content

Recommended Posts

Posted

I need to write a code in which I am reading a text file which is of .vbs format and in that a line contains function signature like below

Function CreateEnvironmentVariable($sType, $sName, $sValue, $bOverwrite)

If the string is in above format, then I need to check number of arguments in it.

For in above case it should return 4.

Can anyone help me on this.

 

  • Moderators
Posted (edited)

@ur what have you tried on your own? Look at FileReadToArray in the help file to read the file in, and parse through it line by line. You can then use StringInStr to parse each line, something like this:

If StringInStr($aArray[$i], "CreateEnvironmentVariable") Then
   ;Count number of params
EndIf

 

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Posted

Got the code...

#include <StringConstants.au3>

$s = "Function CreateEnvironmentVariable($sType, $sName, $sValue, $bOverwrite)"
MsgBox(0,"",CountArgs($s))
Func CountArgs($strFunctionName)
    ;to differentiate between small brackets in strings
    $strFunctionName = StringStripWS($strFunctionName, $STR_STRIPLEADING + $STR_STRIPTRAILING)
    $strFunctionName = StringReplace ( $strFunctionName, "(", "~OSBS~" , 1 )
    $strFunctionName = StringReplace ( $strFunctionName, ")", "~OSBE~" , -1 )
    $strFunctionName = StringReplace ( $strFunctionName, "(", "~DSBS~" )
    $strFunctionName = StringReplace ( $strFunctionName, ")", "~DSBE~" )
    $strFunctionName = StringReplace ( $strFunctionName, "~OSBE~" ,")", -1 )
    $strFunctionName = StringReplace ( $strFunctionName, "~OSBS~","(", 1 )


   Local $arrStrProcedureArguments = StringSplit ( $strFunctionName, "," )
    ;_ArrayDisplay($arrStrProcedureArguments)
    Return $arrStrProcedureArguments[0]
EndFunc

 

Posted

That would have been helpful in post 1 :) So what, exactly, is not working for you?

Yeah it is working fine now, I got the solution after posting the question.So I posted my code here.

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
×
×
  • Create New...