I want to split mystring to get D9167D56488AFF03 value in variable....in below script I am trieng the same but no success, I know my code is wrong...

Set objfso = Createobject("scripting.filesystemobject")
Set objshell = Createobject("wscript.shell")
Const ForReading = 1
Const ForWriting = 2
Set objFile = objFSO.OpenTextFile("C:\config.cfg", ForReading)
strcontents = objFile.ReadAll
mystring = Chr(34) & "/AgentSetup/defaultAccount" & Chr(34) & " = { REPLACE = " & Chr(34) & "cibasc\\sa-bmccommunication/D9167D56488AFF03" & Chr(34) & " },"
msgbox mystring
A = Chr(34) & "/AgentSetup/defaultAccount" & Chr(34) & " = { REPLACE = " & Chr(34) & "cibasc\\sa-bmccommunication/"
arrcontents = Split(strcontents, vbnewline)

For Each strline in arrcontents
if instr(1,Lcase(strline),"A",1) then
arrpassword = Split(strline,"/")
end if
Next

strPassword = arrpassword(1)

msgbox strPassword
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
I don't have your file to test with but try altering the code so that you exit the For...Next loop once you have your data. Also note the trick of directly using Split: For Each strline in arrcontents
if instr(1,Lcase(strline),"A",1) then
'arrpassword = Split(strline,"/")
strPassword = Split(strline,"/")(1)
Exit For
End If
Next


And *do* try and remember to use the CODE tag when posting code or other lengthy text. You access it by using the button marked '<%' or, more quickly, enclosing the word 'code' in square brackets as the starting tag and, for the end tag, use '/code' enclosed in the same way.
Answered 08/25/2009 by: VBScab
Red Belt

Please log in to comment
0
if instr(1,Lcase(strline),"A",1) then - doesnt the Instr method return an integer? In which case, shouldn't this be if instr(1,Lcase(strline),"A",1) > 0 thenand also if you're doing a text comparison do you need 'LCase' ??
Answered 08/25/2009 by: captain_planet
Third Degree Brown Belt

Please log in to comment
0
I tried it, but not working. below is my config.cfg file, in which i have to replace D9167D56488AFF03, with my password....I do not want to keep it hardcoded..
[PATROL_CONFIG
"/AgentSetup/PerfMaxRestartCount" = { REPLACE = "25" },
"/AgentSetup/cos/maxNumRetries" = { REPLACE = "-1" },
"/AgentSetup/cos/retryPeriod" = { REPLACE = "60" },
"/AgentSetup/defaultAccount" = { REPLACE = "cibasc\\sa-bmccommunication/D9167D56488AFF03" },
"/MSEXCHSetup/ExchProductVersion" = { REPLACE = "2000" },
"/MSEXCHSetup/isAccountConfigured" = { REPLACE = "0" }
]
Answered 08/25/2009 by: abking99
Second Degree Blue Belt

Please log in to comment
0
Split(strline,"/")(1) - nifty, VBScab. Very nifty indeed....
Answered 08/25/2009 by: captain_planet
Third Degree Brown Belt

Please log in to comment
0
abking, did you actually test what I posted here??? http://itninja.com/question/faulttree-101522 ....and obviously adapt the code to suit your needs here?
Answered 08/25/2009 by: captain_planet
Third Degree Brown Belt

Please log in to comment
0
The first problem I see is that you're trying to use "A" as a literal string in your if instr line. Try removing the quotation marks, that will tell VB to use the variable you set earlier instead of just the letter A.
Answered 08/25/2009 by: Jsaylor
Second Degree Blue Belt

Please log in to comment
0
you're trying to use "A" as a literal string - ha ha good spot....
Answered 08/25/2009 by: captain_planet
Third Degree Brown Belt

Please log in to comment
0
yes..thanks for that. It is perfect but to make my script more robust, I wanted to take value after
cibasc\\sa-bmccommunication/
because it may change on different machines. So I wanted to store that value in variable.
Answered 08/25/2009 by: abking99
Second Degree Blue Belt

Please log in to comment
0
Do you need to include that value at all? As far as I can tell, you're just trying to locate the specific line with the variable you're setting, I have a feeling that everything including and preceeding "cibasc\\sa-bmccommunication/" is all you need, that string seems unique enough to me.

Remember, you don't have to search for an entire line, just a part of it that is unique to the rest of the text file.
Answered 08/25/2009 by: Jsaylor
Second Degree Blue Belt

Please log in to comment
0
if I am removing quaotation of A then, it is displaying Agentsetup as password, it should show D9167D56488AFF03
Answered 08/25/2009 by: abking99
Second Degree Blue Belt

Please log in to comment
1
Yeah, your array command (strPassword = arrpassword(1) ) is going to set it to return whatever is between the first and second "/" in the string. From the text you showed us, you would want to change it to:

strPassword = arrpassword(3)

EDIT: actually, you might have to do some more splitting, it looks like you have additional characters at the end of the password itself that will need to be removed, your line will actually have to be:

strPassword = split(arrpassword(3),chr(34))(0)
Answered 08/25/2009 by: Jsaylor
Second Degree Blue Belt

Please log in to comment
0
hey it worked...thanks a lot
Answered 08/25/2009 by: abking99
Second Degree Blue Belt

Please log in to comment
0
doesnt the Instr method return an integer? In which case, shouldn't this be Strictly speaking, yes, but good ol' VBS's treatment of everything as a variant until it's explictly accessed means that it can be evaluated as True/False, 1/0, etc.
Answered 08/25/2009 by: VBScab
Red Belt

Please log in to comment
0
Hi,
as per your last post I am able to store password in strpassword1 in below code

[A = Chr(34) & "/AgentSetup/defaultAccount" & Chr(34) & " = { REPLACE = " & Chr(34) & "cibasc\\sa-bmccommunication/"
arrcontents = Split(strcontents, vbnewline)
For Each strline in arrcontents
if instr(1,(strline),A,1) then
arrpassword = Split(strline,"/")
exit for
end if
Next
strpassword1 = split(arrpassword(3),chr(34))(0)
msgbox strpassword1]

now I am using this strpassword1 in below code:
[lineToReplace = Chr(34) & "/AgentSetup/defaultAccount" & Chr(34) & " = { REPLACE = " & Chr(34) & "cibasc\\sa-bmccommunication/strpassword1" & Chr(34) & " },"
msgbox lineToReplace]

but it is not getting resolved, in "msgbox lineToReplace"
Answered 08/25/2009 by: abking99
Second Degree Blue Belt

Please log in to comment
0
This: lineToReplace = Chr(34) & "/AgentSetup/defaultAccount" & Chr(34) & " = { REPLACE = " & Chr(34) & "cibasc\\sa-bmccommunication/strpassword1" & Chr(34) & " },"

should be like this:


lineToReplace = Chr(34) & "/AgentSetup/defaultAccount" & Chr(34) & " = { REPLACE = " & Chr(34) & "cibasc\\sa-bmccommunication/" & strpassword1 & Chr(34) & " },"

Note the quote/ampersand before 'strpassword1' and no quote after it....
Answered 08/25/2009 by: captain_planet
Third Degree Brown Belt

Please log in to comment
Answer this question or Comment on this question for clarity