/build/static/layout/Breadcrumb_cap_w.png

split string

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

Answers (15)

Posted by: Jsaylor 14 years ago
Second Degree Blue Belt
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)
Posted by: anonymous_9363 14 years ago
Red Belt
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.
Posted by: captain_planet 14 years ago
Black Belt
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' ??
Posted by: abking99 14 years ago
Second Degree Blue Belt
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" }
]
Posted by: captain_planet 14 years ago
Black Belt
0
Split(strline,"/")(1) - nifty, VBScab. Very nifty indeed....
Posted by: captain_planet 14 years ago
Black Belt
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?
Posted by: Jsaylor 14 years ago
Second Degree Blue Belt
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.
Posted by: captain_planet 14 years ago
Black Belt
0
you're trying to use "A" as a literal string - ha ha good spot....
Posted by: abking99 14 years ago
Second Degree Blue Belt
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.
Posted by: Jsaylor 14 years ago
Second Degree Blue Belt
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.
Posted by: abking99 14 years ago
Second Degree Blue Belt
0
if I am removing quaotation of A then, it is displaying Agentsetup as password, it should show D9167D56488AFF03
Posted by: abking99 14 years ago
Second Degree Blue Belt
0
hey it worked...thanks a lot
Posted by: anonymous_9363 14 years ago
Red Belt
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.
Posted by: abking99 14 years ago
Second Degree Blue Belt
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"
Posted by: captain_planet 14 years ago
Black Belt
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....
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ