related sites: <FREE Help> <ASP> <Asp.net> <worldwide> feedback: <lovethat> <hatethat> <thanks> <credits> <contact us>
Making webs automatically <Next>
From: Dan Pumphrey <dpumphre@ai.org> Organization: Access Indiana Subject: [asp advanced] advanced file manipulation...
First off I want to say thanks to everyone who provided suggestions to my problem yesterday - This list is great! Most lists that I belong to you can never get an answer to your question...
Enough noise - to the good stuff: I have a text file with the following format: username:password username:password username:password ... Basically an apache passwd file - what I want to do is this: 1) Open file and find line with the username that was supplied via a form 2) once that line is found split it on the ":" and read the values into an array 3) Then I need to extract the first 2 chars from array(2) and save them as a separate string
I don't necessarily need someone to write the code and give it to me - I just can not find any information on Advanced File manipulation - I have WROX's Professional ASP book and it goes over basic opening and closing, reading the whole file as a string, etc. If anyone has some good links relating to Advanced file manipulation I would appreciate seeing them.
here is an example of how the code might look in perl: open (FILE, "$filename"); if (/$username/) { @array = split /:/; if $pass = $array[2]; {&letthemin} } close (FILE) Thanks again Daniel Pumphrey
From: Manohar Kamath <mkamath@niu.edu> Subject: Re: [asp advanced] advanced file manipulation...
Perl is still a great string manipulation language, owing to the Regular expressions. In your case, there is no one way of doing it. However, this is the pseudo-code.
Open the file Array[i, j] sLine = Read a line from the file Do while Not end of File Parse the string for : Do While Not End of string When found copy to Array[i, j] j = j+ 1 Parse String for : End Do i = i + 1 sLine = Read a line from the file End Do While I can't talk about a component (mine) which does this, I can surely give you the code that parse the line. You will have to build on that for the file Loop. Here it is: ' Initialize the variables used in the function Dim arValues() ' If invalid strings, exit function If sParseString = "" Or sDelimitor = "" Then StringToArray = arValues Exit Function End If lStart = 1 iCount = 0 lLen = Len(sParseString) iDelimLen = Len(sDelimitor) ' Initialize the parsing lPos = InStr(lStart, sParseString, sDelimitor) ' Loop through the string Do While lPos > 0 ' Resize the array and add the new segment ReDim Preserve arValues(iCount) arValues(iCount) = Mid(sParseString, lStart, lPos - lStart) iCount = iCount + 1 lStart = lPos + iDelimLen lPos = InStr(lStart, sParseString, sDelimitor) Loop ' Check for any remnant string If lStart <= lLen Then ReDim Preserve arValues(iCount) arValues(iCount) = Mid(sParseString, lStart) End If ' Return the array StringToArray = arValues -- Manohar Kamath http://www.kamath.com/books Visit us !
From: James Page <James.Page@Cedalion.co.uk> Subject: RE: [asp advanced] advanced file manipulation... Date: Thu, 16 Apr 1998 09:46:43 +0100
I agree, Perl is probably going to be a lot easier for you if you are going to be parsing files. You can download the PerlScript engine from the ActiveWare site - http://www.activeware.com.
Also, did you know that JScript version 3.0 (that comes with IIS 4.0) also allows you to use regular expressions? Check out http://localhost/iishelp/jscript/htm/js596.htm, or the following Microsoft article: http://www.microsoft.com/sitebuilder/workshop/prog/ie4/jscript3.htm which details new JScript features.
%%%%%%%%%%%%%%%%% % % James Page % Cedalion Ltd. % 27 Maritime Street % Leith, Edinburgh, UK % http://www.cedalion.co.uk % %%%%%%%%%%%%%%%%%
From: Richard Walker <Richard.Walker@west-server.com> Organization: West Engineering Subject: Re: [asp advanced] advanced file manipulation...
James Page wrote: > Also, did you know that JScript version 3.0 (that comes with IIS 4.0) > also allows you to use regular expressions?
Just want to point out that JavaScript 1.2, which works with Netscape Communicator (4.x) also has a RegExp object that allows for perl-like parsing of regular expressions. To find out more about this object, visit http://developer.netscape.com/docs/manuals/communicator/jsref/corea3.htm#1158210 I personally find this documentation very concise, and it should conform to the JScript docs mentioned above.
-- Richard Walker Systems Administrator, Webmaster West Engineering