Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old December 4th, 2004, 01:47 PM
Ruffio Ruffio is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 8 Ruffio User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 1 m 29 sec
Reputation Power: 0
Lightbulb Replacing a character at the start of a line in txt

How can I search a txt file line per line and check if the line starts with the character "#".And since I have found that character,how can I erase it or just replace it with " ".Here's a sample text:

# The index.html.var file (a type-map) is used to deliver content-
# negotiated documents. The MultiViews Option can be used for the
# same purpose, but it is much slower.
#
DirectoryIndex index.html index.html.var
#
# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives. See also the AllowOverride
# directive.

Reply With Quote
  #2  
Old December 4th, 2004, 03:54 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 21 h 32 m 23 sec
Reputation Power: 180
If Left(theStr, 1) = "#" Then
'found it
End If

fixStr = Mid(theStr, 2, Len(theStr))
__________________
======
Doug G
======
I didn't attend the funeral, but I sent a nice letter saying I approved of it. --Mark Twain

Reply With Quote
  #3  
Old December 5th, 2004, 08:19 PM
Ruffio Ruffio is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 8 Ruffio User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 1 m 29 sec
Reputation Power: 0
Talking Thanks

Quote:
Originally Posted by Doug G
If Left(theStr, 1) = "#" Then
'found it
End If

fixStr = Mid(theStr, 2, Len(theStr))
Thanks for the tip my friend!I only have one question:what's the fixStr stand for,as a function I mean.And what is included in the "if" loop,except the comment?Thanks again!

Reply With Quote
  #4  
Old December 5th, 2004, 08:48 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 21 h 32 m 23 sec
Reputation Power: 180
fixStr is just a variable name I made up.

You'd probably want to put the code to remove the # in the If block.

Reply With Quote
  #5  
Old December 6th, 2004, 06:02 PM
Ruffio Ruffio is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 8 Ruffio User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 1 m 29 sec
Reputation Power: 0
Question About

In case I want to check each line if it begins with the "#",how can I go from the first line to the second,the third etc...?

Reply With Quote
  #6  
Old December 6th, 2004, 07:54 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 21 h 32 m 23 sec
Reputation Power: 180
Depends on what code you're using to get the lines to check. Post some code maybe?

Reply With Quote
  #7  
Old December 7th, 2004, 03:48 PM
Ruffio Ruffio is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Dec 2004
Posts: 8 Ruffio User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 1 m 29 sec
Reputation Power: 0
Red face Help..please?

Private Sub Option1_Click()
Dim rline
Dim Counter As String
Dim searchar
Dim chk
searchar = "#"
chk = InStr(0, rline, searchar)

Open testfile For Input As #1 'Open the text file
Line Input #1, rline 'grab first line
Debug.Print rline
Counter = 1 'start counter
Do While Not EOF(1) 'Continue to EOF = true

If Counter = 1 & chk = 0 Then
Text1.Text = rline
Else
'No
If chk <> 0 Then
Counter = 0 'reset the counter
Text2.Text = rline
End If
End If
Line Input #1, rline 'Get next record
Counter = Counter + 1 'Increment counter
Loop
Close #1

End Sub
........................................
The code above seems to read only the last line before the end of the file,although if it worked properly,it should read each line seperately.If at the start of the line grabbed,the "#" character is spotted,the string that follows is sent into a textbox.If there's no "#" at the start of the line,the following string goes to another textbox.How is it possible to make the program read each line of the textfile loaded seperately,check if the starting character of each line is "#" and then store or just view the following strings?Help....

Reply With Quote
  #8  
Old December 7th, 2004, 08:56 PM
Doug G Doug G is offline
Grumpier Old Moderator
ASP Free God 11th Plane (10000 - 10499 posts)
 
Join Date: Sep 2003
Posts: 10,143 Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level)Doug G User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 3 Weeks 4 Days 21 h 32 m 23 sec
Reputation Power: 180
You are setting chk before you read the line. Move that test after you have read the line.

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > Replacing a character at the start of a line in txt


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway