I've been using this technique in several of my programs now for quite a while and haven't had any kind of trouble with it until now. Granted now things have gotten a bit trickier but I'm still doing the same basic concept of search through a string looking for a pointer at the start and at the end of the string and then I'm copying what is in between to a new string.

Dim string1 as string, string2 as string, stringURL as string, strMid as string, strHeight as string

stringURL="<p>This is a good time for every man, woman and child to come to their wits, senses, smarts and bravery</p>"
string1 = "every"
string2 = "</p>"
loc = InStr(1, stringURL, string1)
If loc = 0 Then GoTo nxtFile
lng = Len(stringURL) - loc - 4
strMid = Right(stringURL, lng)
            
loc = InStr(1, strMid, string2)
If loc = 0 Then GoTo nxtFile
strHeight = Left(strMid, (loc - 1))

Msgbox strHeight

nxtFile:
End Sub

The above sentence always comes out:
every manwoman and child to come to their witssensessmarts and bravery

It always seems to remove the comma and the trailing space(where it exists).

Why is this behaving like this. I'm not sure if I've tried this without it being part of html code or not to see what happens. I need it right now though for a program that is dumping a lot of html code and shortening up the pages the make them look and feel the way I want them to.

Recommended Answers

All 2 Replies

Its working to me..I run your codes and i got string with commas inside.

Did you do it by using a saved html file. That is what I'm saying. I have a html file saved on my hard drive and I'm trying to go and edit the html file down in size and in appearance. When I do that the commas don't ever transfer over like they normally do with regular text. In the above code it works fine since your doing it with regular code. For some reason when I try to do it with an html file the commas aren't copying over. For that matter when I run the following code no commas pop up in the msgbox. The html file is 12.6Kb and the only way I've found to copy the code into a string is to do it the way I have indicated below. Yeah, I'm just using the Pause right now for testing different things out...it's rather handily available at the present time.

Private Sub Pause_Click()

Dim strMid As String, stringURL As String
    
    filepath = "D:\JB\"
    FileName2 = "9.htm"
    strMid = ""
    Open filepath & FileName2 For Input As #1

    Do While Not EOF(1)
        Input #1, stringURL
        strMid = strMid & stringURL
    Loop
    Close #1
    stringURL = strMid
        
    MsgBox stringURL
    
End Sub
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.