Webmaster Forum

Go Back   Webmaster Forum > Scripting/Programming & Debugging > ASP & VBScript Forum
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

ASP & VBScript Forum Need help from a webmaster with ASP or VBScript, you may ask in this forum?

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-31-2007, 03:33 AM
peachtea peachtea is offline
Junior Member
 
Join Date: Jul 2007
Posts: 4
peachtea is an unknown quantity at this point
Submit to Clesto Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Jeqq Submit to Spurl
Default Mid Function. Reading of files

hi

I need help in reading some text in a textfile. I can read line by line but what i wanted is to read character by character

Example
Mary had a little lamb
Jane had a little dogs

I want the name of the person as well as the animal type and i wrote:

Dim person : person = Mid(testfile.ReadLine, 1,4)
Dim animal : animal = Mid(testfile.ReadLine, 19,4)

but the output will be "Mary" and "dogs"

whereby i wld need the output to be:
"Mary" "lamb"
"Jane" "dogs"

Pls help. Thanks alot
Reply With Quote

This ad is part of our Revenue Sharing program
  #2 (permalink)  
Old 08-01-2007, 01:33 AM
ALL's Avatar
ALL ALL is offline
Senior Member
 
Join Date: Oct 2006
Location: Sturgis, SD
Posts: 145
ALL is on a distinguished road
Submit to Clesto Submit to Digg Submit to Reddit Submit to Furl Submit to Del.icio.us Submit to Jeqq Submit to Spurl
Default

you should try regular expressions, it makes life alot eassier in the long run, even though microsoft makes regexs hard to use...

Code:
mystring = "Mary had a little lamb" Set regexp = New RegExp regexp.Pattern = "^([a-zA-Z]+) .* ([a-zA-Z]+)$" regexp.IgnoreCase = False regexp.Global = False Set matches = regexp.Execute(mystring) document.writeln(matches(0).SubMatches(0) + " is a name<br>") document.writeln(matches(0).SubMatches(1) + " is an animal<br>")
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 02:33 AM.


Creative Commons License
Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.0.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30