alpizzle
-
Total Posts
:
6
- Scores: 0
-
Reward points
:
0
- Joined: 4/16/2008
-
Status: offline
|
InStr / Right function
Wednesday, April 16, 2008 12:47 AM
( permalink)
Hi Guys, I'm kind of new to programming and have a question about an asp page that uses vbscript that I need to alter. What happens now is I have a user upoad a file, my program looks for certain things using InStr, for example If Instr(1, strline, "Label="), it then copies the next line to a numbered line in a destination file. Now I have a new set of files being uploaded that aren't as uniformly formatted as above. So I need to look for ":" in a string, which could be at any position and copy everything after the colon to the numbered line. I am unsure how to approah this and could use any advice that could point me in the right direction. Thanks
|
|
|
|
ebgreen
-
Total Posts
:
8227
- Scores: 98
-
Reward points
:
0
- Joined: 7/12/2005
-
Status: offline
|
RE: InStr / Right function
Wednesday, April 16, 2008 1:48 AM
( permalink)
There are a couple of ways to do this. The way I would do it is this: 'strLine is the line you want to look for the data in If InStr(strLine, ":") Then strData = Split(strLine, ":")(1) End If
|
|
|
|
alpizzle
-
Total Posts
:
6
- Scores: 0
-
Reward points
:
0
- Joined: 4/16/2008
-
Status: offline
|
RE: InStr / Right function
Wednesday, April 16, 2008 2:08 AM
( permalink)
wow, thanks ebgreen, I was making that waaaay more dificult than it needed to be. I appreciate the help
|
|
|
|
alpizzle
-
Total Posts
:
6
- Scores: 0
-
Reward points
:
0
- Joined: 4/16/2008
-
Status: offline
|
RE: InStr / Right function
Wednesday, April 16, 2008 3:19 AM
( permalink)
Sorry to ask but one more question if you could help. It appears way down the file there are some lines that have multiple colons on each line, any tips on that? I am using the code as you suggested and it's fantastic for 99% of the lines If InStr(strLine, ":") Then strData = Split(strLine, ":")(1) streamDestFile.WriteLine phNumber & " " & strData phNumber = phNumber + 1 End If
|
|
|
|
ebgreen
-
Total Posts
:
8227
- Scores: 98
-
Reward points
:
0
- Joined: 7/12/2005
-
Status: offline
|
RE: InStr / Right function
Wednesday, April 16, 2008 3:55 AM
( permalink)
Could you show some of the problematic lines?
|
|
|
|
alpizzle
-
Total Posts
:
6
- Scores: 0
-
Reward points
:
0
- Joined: 4/16/2008
-
Status: offline
|
RE: InStr / Right function
Wednesday, April 16, 2008 4:10 AM
( permalink)
Sure thing, here are a couple of examples: CHANNEL_READING_STATS:%d readings on Chan %d: Avg: %s Min: %d Max: %d Alt: Avg: %s Min: %d Max %d FSC_NEXT_LOOP_6_STR5: Note: Lateral channel tare replaces offset in normal operation. Basically I need everything left of the first colon removed, which would write line numbers and the remainder of the string to the destination file. Like the following: 1 Note: Lateral channel tare replaces offset in normal operation. Thanks ebgreen
|
|
|
|
ebgreen
-
Total Posts
:
8227
- Scores: 98
-
Reward points
:
0
- Joined: 7/12/2005
-
Status: offline
|
RE: InStr / Right function
Wednesday, April 16, 2008 4:16 AM
( permalink)
Oh, so would this statement apply to all lines? "If a colon is present then the data of interest is everything after the first colon"
|
|
|
|
alpizzle
-
Total Posts
:
6
- Scores: 0
-
Reward points
:
0
- Joined: 4/16/2008
-
Status: offline
|
RE: InStr / Right function
Wednesday, April 16, 2008 4:19 AM
( permalink)
|
|
|
|
ebgreen
-
Total Posts
:
8227
- Scores: 98
-
Reward points
:
0
- Joined: 7/12/2005
-
Status: offline
|
RE: InStr / Right function
Wednesday, April 16, 2008 4:40 AM
( permalink)
Remeber that "There are a couple of ways..." statement? Well we are going to go a different way 'strLine is the line you want to look for the data in strData = Mid(strLine, InStr(strLine, ":")+1)
|
|
|
|
alpizzle
-
Total Posts
:
6
- Scores: 0
-
Reward points
:
0
- Joined: 4/16/2008
-
Status: offline
|
RE: InStr / Right function
Wednesday, April 16, 2008 5:55 AM
( permalink)
Thanks so much for the help ebgreen, I really appreciate it, that worked very well.
|
|
|
|