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
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)
Please log in to answer
Posted by:
Jsaylor
15 years ago
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)
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
15 years ago
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:
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.
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
15 years ago
Posted by:
abking99
15 years ago
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" }
]
[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
15 years ago
Posted by:
Jsaylor
15 years ago
Posted by:
captain_planet
15 years ago
Posted by:
abking99
15 years ago
Posted by:
Jsaylor
15 years ago
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.
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
15 years ago
Posted by:
anonymous_9363
15 years ago
Posted by:
abking99
15 years ago
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"
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
15 years ago
This:
should be like this:
Note the quote/ampersand before 'strpassword1' and no quote after it....
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.
so that the conversation will remain readable.