PDA

View Full Version : Reading a paragraph


Brad
03-06-2003, 09:26 AM
Good morning,

Could someone take a look at this, please ?

This follows on from a previous help I received, which helped me to select certain elements from a text file. I have a user and password list, which is just a text file, with lots of paragraphs like this:

Firstname_Secondname Password="whatever"
Service-Type=Framed,
Framed-protocol=PPP,
Ascend-Send-Auth = Send-Auth-None,
Ascend-Route-IP=Route-IP-Yes,
Ascend-Metric=1,
Ascend-Data-Svc = Switched-128K,
Framed-Routing=None,
Ascend-Idle-Limit = 1200,
Ascend-Assign-IP-Pool=3

I needed to retrieve the username and password only. I was kindly given this code to use, which worked perfectly:

SQLStr = "SELECT Left([Field1],InStr([Field1],' Password')-1) AS Username, Mid([Field1],InStr([Field1],Chr(34))+1,Len([Field1])-InStr([Field1],Chr(34))-1) AS Password FROM Users WHERE (((Users.Field1) Like '%" & delimiter & "%' & '" & pws & "%'));"

However, is it possible to create a piece of code which will read all the above lines above upto the next blnak line, then start again ???

Thanks, as always, in advance,
Brad.

raf
03-06-2003, 11:41 AM
of coarse, it is non of my business, buth why not have an XML file ? Querying that is a lot easier and more flexible.

Brad
03-06-2003, 11:59 AM
Thanks, Raf,

Unfortunately, though, that throws me into a whole new field of disarray - i've never used xml

whammy
03-07-2003, 01:23 AM
Just use FSO (Scripting.FileSystemObject) then, if you're reading from a text file... and add each line to a string until you run into a blank line, in which case you determine what else to do...

If you work a lot with text files (as I have to, since the clients/business partners we deal with don't use XML yet), you HAVE to learn this - I would suggest going here and learning/experimenting with everything (I learned all of it here pretty much) until you understand FSO enough to manipulate files the way you want to with ASP. It's not very hard, actually, if you just go through all of these examples:

http://www.w3schools.com/asp/asp_ref_filesystem.asp

Also, I would make sure you have a grasp of fundamental String Manipulation in ASP, such as using InStr(), Split(), InStrRev(), Mid(), Left(), Right(), etc.

If you learn FSO and the string manipulation techniques above (which are in all beginner's books, like "Beginning ASP 3.0" by Wrox.com - although with a google search you could probably learn them as well), then you won't have any problem manipulating text files!


XML gives you a lot more powerful options though... for text files you have to adapt your scripts to parse whatever that particular text file should usually contain. But this is a very good start, and a necessity for anyone that works with text files that uses ASP (not to mention it helps with StreamReader and StreamWriter in .NET whenever you get into .NET).