#111970 - 2004-01-20 10:19 PM
Re: Spliting a String
|
maciep
Korg Regular
Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
|
What about something like this? I think it will work, if i understood your conditions correctly
Code:
$nums = "1234567890" $letters = "SNKEHMRL" $computer = "S123N56" $computerName = "Failed" $stillGood = 1 if instr("WLS", left($computer, 1)) and len($computer) = 7 if left($computer, 1) = "S" for $j = 2 to 4 if not instr($nums, substr($computer, $j, 1)) $stillGood = 0 endif next
for $j = 6 to 7 if not instr($nums, substr($computer, $j, 1)) $stillGood = 0 endif next
if instr($letters, substr($computer, 5, 1)) and $stillGood $computerName = "Store" endif else for $j = 2 to 7 if not instr($nums, substr($computer, $j, 1)) $stillGood = 0 endif next if $stillGood $computerName = "Corp" endif endif endif
? $computerName
_________________________
Eric
|
Top
|
|
|
|
#111974 - 2004-01-21 02:25 AM
Re: Spliting a String
|
maciep
Korg Regular
Registered: 2002-06-14
Posts: 947
Loc: Pittsburgh
|
So, if 'S' will definitely only be 8 or 9 chars long and 'W/L' will be only 7 or 8 char long, this should work. If they could be longer, just change the $len comparison's to >7 and >6 respectively. Should work.
Code:
$nums = "1234567890" $letters = "SNKEHMRL" $computer = "S1253K59A" $computerName = "Failed" $stillGood = 1 $len = len($computer) if instr("WLS", left($computer, 1)) if left($computer, 1) = "S" and ($len = 8 or $len = 9) for $j = 2 to 5 if not instr($nums, substr($computer, $j, 1)) $stillGood = 0 endif next
for $j = 7 to 8 if not instr($nums, substr($computer, $j, 1)) $stillGood = 0 endif next
if instr($letters, substr($computer, 6, 1)) and $stillGood $computerName = "Store" endif else if $len = 7 or $len = 8 for $j = 2 to 7 if not instr($nums, substr($computer, $j, 1)) $stillGood = 0 endif next if $stillGood $computerName = "Corp" endif endif endif endif
? $computerName
_________________________
Eric
|
Top
|
|
|
|
Moderator: Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart
|
0 registered
and 515 anonymous users online.
|
|
|