|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
Quote:
|
|
#4
|
|||
|
|||
|
fixStr is just a variable name I made up.
You'd probably want to put the code to remove the # in the If block. |
|
#5
|
|||
|
|||
|
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...?
|
|
#6
|
|||
|
|||
|
Depends on what code you're using to get the lines to check. Post some code maybe?
|
|
#7
|
|||
|
|||
|
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.... |
|
#8
|
|||
|
|||
|
You are setting chk before you read the line. Move that test after you have read the line.
|
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Replacing a character at the start of a line in txt |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|