Page 2 of 2 <12
Topic Options
#111970 - 2004-01-20 10:19 PM Re: Spliting a String
maciep Offline
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
#111971 - 2004-01-20 10:37 PM Re: Spliting a String
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I dunno... maybe it's just me getting cross-eyed trying to follow the logic... but if your indenting is true to form, the following have only a single CASE:
Case $sLocation >= "0002" AND $sLocation <= "0999"
Case InStr('NLRHEKSV',$sFunction)

I take back the ELSE part.
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#111972 - 2004-01-20 11:06 PM Re: Spliting a String
ArchAngel96 Offline
Getting the hang of it

Registered: 2002-10-20
Posts: 70
Man, I've been staring at this script for four days now. All i know is it works exactly how I need it to... lol

Ok, ok... Maybe there is a spot or two I could use 'If', but I really don't want to chance breaking what's now working...lol

After I look at some other scripts I'll see about cleaning it more... fresh eyes and all

Didn't see maciep message first time around.

I like that one better. But I'm testing it and it doesn't like 4 numbers starting with zero. I have to keep that due to our numbers growing regularly...
Line 8:
Code:
       For $j = 2 to 4 


doesn't appear to like 0123 or any other combination. But it should work based on how I'm reading your code.


Edited by ArchAngel96 (2004-01-20 11:29 PM)
_________________________
penny = the target the playing field = three football fields side by side you = only allowed to stand on the outside of the playing field tool you get to use to find the penny = a ONE INCH LAWN DART get the level of difficulty?

Top
#111973 - 2004-01-20 11:50 PM Re: Spliting a String
ArchAngel96 Offline
Getting the hang of it

Registered: 2002-10-20
Posts: 70
Ok I see where the issue is. I think it still needs to be broken up to WL and S sections.

WL will have 6 munbers following for a correct name. For a total of 7 characters.

S will have 4 numbers, a letter and 2 more numbers a total of 8 characters.

Also on a RARE occation our techs didn't know how to add the computer onto the domain correctly so some W/L machines have and extra 'character' of some kind after.. Still need to check for that. So I'll have to do some modifications...


Edited by ArchAngel96 (2004-01-20 11:57 PM)
_________________________
penny = the target the playing field = three football fields side by side you = only allowed to stand on the outside of the playing field tool you get to use to find the penny = a ONE INCH LAWN DART get the level of difficulty?

Top
#111974 - 2004-01-21 02:25 AM Re: Spliting a String
maciep Offline
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
Page 2 of 2 <12


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 515 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.055 seconds in which 0.025 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org