Login | |
|
 |
RE: how to split - 6/12/2007 6:15:44 AM
|
|
 |
|
| |
ebgreen
Posts: 4946
Score: 31
Joined: 7/12/2005
Status: online
|
If the format of the string is always the same (6 words sperated by spaces) and the part that you want is always the same (the first andthird parts) then this will work: strTest = "HP Compaq dc510 Small Form Factor" arrParts = Split(strTest, " ") WScript.Echo arrParts(0) & " " & arrParts(2)
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: how to split - 6/12/2007 6:51:04 AM
|
|
 |
|
| |
sheepz
Posts: 247
Score: 2
Joined: 3/17/2006
From: Riverside the 909s
Status: offline
|
thanks ebgreen... i didn't know i could split with: arrParts = Split(strTest, " ") i thought i had to have a delimiter of some sort. thank you again. =)
|
|
| |
|
|
|
 |
RE: how to split - 6/12/2007 9:44:04 AM
|
|
 |
|
| |
sheepz
Posts: 247
Score: 2
Joined: 3/17/2006
From: Riverside the 909s
Status: offline
|
i didn't know a space was a valid delimiter, thanks. sorry another question. for the make/models they come up like so: Comp_Model = "HP d530 SV(79285)" Comp_Model = "HP Compaq dc7600 Small Form Factor" so i want to differenciate from these two types using Select but having problems. i'm trying to use InStr but it keeps using the 2nd case statement even tho theres a "d5" in the string... Select Case TypeModel Case InStr(Comp_Model, "d5") arrParts = Split(Comp_Model, " ") Comp_Model_Split = arrParts(0) & "-" & arrParts(1) Case InStr(Comp_Model, "7") arrParts = Split(Comp_Model, " ") Comp_Model_Split = arrParts(0) & ":" & arrParts(2) Case Else arrParts = Split(Comp_Model, " ") Comp_Model_Split = arrParts(0) & "=" & arrParts(1) & _ arrParts(2) End Select WScript.Echo comp_model_split i'm using the select statement incorrectly. it works if i revise to if statement
< Message edited by sheepz -- 6/12/2007 9:50:17 AM >
|
|
| |
|
|
|
 |
RE: how to split - 6/12/2007 10:21:02 AM
|
|
 |
|
| |
sheepz
Posts: 247
Score: 2
Joined: 3/17/2006
From: Riverside the 909s
Status: offline
|
how does it figure that InStr(CompModel,"d5") was > 0 how is this less than 0? and InStr(CompModel,"7") = 0 how is this equal to 0? whats the logic? does select automatically take the first case1 as >0 and the case2 =0. would case3 be <0? do these lines: InStr(CompModel, "7") have values? i would like a select statement that does not contain >0
|
|
| |
|
|
|
 |
RE: how to split - 6/12/2007 11:06:20 AM
|
|
 |
|
| |
sheepz
Posts: 247
Score: 2
Joined: 3/17/2006
From: Riverside the 909s
Status: offline
|
i used that as an example but still unsure how it works... i understand that Select Case tests each case, once a true case is found it executes, and the rest of the case statements are ignored... when skie showed me what i was doing wrong, i understood why i was getting the select case2. what i'm a little fuzzy on is how does it know the value of this: Case InStr(Comp_Model, "7") > 0 how is Case InStr(Comp_Model, "7") greater than 0? 2nd question: i thought the name after the select statement is just the name of the statement, meaningless. Select Case TypeModel is the same as putting Select Case TypeModel = 0 ? i'm trying to learn how the Select case works by converting this if statement into select: If InStr(Comp_Model, "5") Then arrParts = Split(Comp_Model, " ") Comp_Model_Split = arrParts(0) & "-" & arrParts(1) ElseIf InStr(Comp_Model, "dc7") Then arrParts = Split(Comp_Model, " ") Comp_Model_Split = arrParts(0) & ":" & arrParts(2) Else arrParts = Split(Comp_Model, " ") Comp_Model_Split = arrParts(0) & "=" & arrParts(1) & _ arrParts(2) End If WScript.Echo Comp_Model_Split what would be the correct conversion? am i converting it correctly?
< Message edited by sheepz -- 6/12/2007 11:18:48 AM >
|
|
| |
|
|
|
 |
RE: how to split - 6/13/2007 1:30:21 AM
|
|
 |
|
| |
ebgreen
Posts: 4946
Score: 31
Joined: 7/12/2005
Status: online
|
If you really want to use Select Case, then you need to use something of a trick: Select Case True Case InStr(Comp_Model, "5") 'Do things here Case InStr(Comp_Model, "dc7") 'Do things here Case Else 'Do things here End Select
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: how to split - 6/14/2007 4:41:30 AM
|
|
 |
|
| |
sheepz
Posts: 247
Score: 2
Joined: 3/17/2006
From: Riverside the 909s
Status: offline
|
Skie, thank you i really appreciate the detailed explanation... its much more clearier with the examples given, thanks. dm_4ever and ebgreen thank you for additional information, still trying to grasp expressions. thanks guys!
|
|
| |
|
|
|
 |
RE: how to split - 7/1/2007 6:55:40 PM
|
|
 |
|
| |
sheepz
Posts: 247
Score: 2
Joined: 3/17/2006
From: Riverside the 909s
Status: offline
|
i'm sorry another question about split. lets say i have a string but i dont want the first array(0) because its always the Username, the rest is group membership which i do need. is this the best way to ignore/bypass the username in this string and retrieve only the membership? strTemp = "JSmith;Accounting;Purchasing;Approver" arrTemp = Split(strTemp, ";") For i = LBound(arrTemp) To UBound(arrTemp) - 1 WScript.Echo arrTemp(i + 1) Next Is works but is this the actual way to go about it?
|
|
| |
|
|
|
 |
RE: how to split - 7/2/2007 12:53:07 AM
|
|
 |
|
| |
dm_4ever
Posts: 2635
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
|
You could also do it like this...it is up to you... strTemp = "JSmith;Accounting;Purchasing;Approver" arrTemp = Split(strTemp, ";") For i = 1 To UBound(arrTemp) WScript.Echo arrTemp(i) Next or backwards strTemp = "JSmith;Accounting;Purchasing;Approver" arrTemp = Split(strTemp, ";") For i = UBound(arrTemp) To 1 Step - 1 WScript.Echo arrTemp(i) Next
_____________________________
dm_4ever My philosophy: K.I.S.S - Keep It Simple Stupid Read Me: http://www.visualbasicscript.com/m_24727/tm.htm Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: how to split - 7/2/2007 3:30:01 AM
|
|
 |
|
| |
sheepz
Posts: 247
Score: 2
Joined: 3/17/2006
From: Riverside the 909s
Status: offline
|
awesome dm, didn't know i could do that, much simpler, thanks. =)
|
|
| |
|
|
|
 |
RE: how to split - 7/2/2007 3:44:00 AM
|
|
 |
|
| |
ebgreen
Posts: 4946
Score: 31
Joined: 7/12/2005
Status: online
|
Or if you want the last part and you want it formatted as it originally was: strTemp = "JSmith;Accounting;Purchasing;Approver" arrTemp = Split(strTemp, ";") arrTemp(0) = "" WScript.Echo Mid(Join(arrTemp, ";"), 2)
_____________________________
"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: how to split - 7/2/2007 9:59:59 AM
|
|
 |
|
| |
sheepz
Posts: 247
Score: 2
Joined: 3/17/2006
From: Riverside the 909s
Status: offline
|
hi eb, thats a good way too. i'm sorry to ask but could you explain this line: Mid(Join(arrTemp, ";"), 2) i'm not sure what Mid is for and the 2. as for the join, it means to join the rest of arrTemp with ; after each element?
|
|
| |
|
|
|
|
|