Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

how do i detemen how long a text string...

is in between "hi" and the end of the line
[42 byte] By [Code_Writer] at [2007-11-11 7:14:28]
# 1 Re: how do i detemen how long a text string...
Use the InStr function to figure out the location of "hi". Then subtract that value from the length of the stirng (returned by the Len function).
Phil Weber at 2007-11-11 17:27:21 >
# 2 Re: how do i detemen how long a text string...
but what about if there is more on the next line?
Code_Writer at 2007-11-11 17:28:21 >
# 3 Re: how do i detemen how long a text string...
Please post an example of the text you want to search and the result you expect.
Phil Weber at 2007-11-11 17:29:22 >
# 4 Re: how do i detemen how long a text string...
[.ShellClassInfo]
IconFile=
IconIndex=0
(there could be text here)

Start at "IconIndex=" and it gose to the end of the line and in this case it should return 0

and this
[.ShellClassInfo]
IconFile=
IconIndex=123
(there could be text here)
should return "123"
Code_Writer at 2007-11-11 17:30:16 >
# 5 Re: how do i detemen how long a text string...
OK, I don't see how that has anything to do with your original question. ;-) I would do this (assuming that these lines are in a disk file):

hFile = FreeFile
Open "d:\path\filename.ini" For Input As hFile
Do Until EOF(hFile)
' Read a line
Line Input #hFile, sText
' If line contains "IconIndex"...
If InStr(sText, "IconIndex") Then
' Find equal sign
Equal = InStr(sText, "=")
' If found...
If Equal Then
' Extract text following equal sign,
' trim spaces and convert to value
IconIndex = Val(Trim(Mid(sText, Equal + 1)))
End If
End If
Loop
Close hFile
Phil Weber at 2007-11-11 17:31:15 >
# 6 Re: how do i detemen how long a text string...
it is in a text box all ready
it is named DesktopText.Text
Code_Writer at 2007-11-11 17:32:25 >
# 7 Re: how do i detemen how long a text string...
Dim Line As Variant
Dim Lines() As String
Lines = Split(DesktopText.Text, vbCrLf)

For Each Line In Lines
' If line contains "IconIndex"...
If InStr(Line, "IconIndex") Then
' Find equal sign
Equal = InStr(Line, "=")
' If found...
If Equal Then
' Extract text following equal sign,
' trim spaces and convert to value
IconIndex = Val(Trim(Mid(Line, Equal + 1)))
End If
End If
Next
Phil Weber at 2007-11-11 17:33:25 >
# 8 Re: how do i detemen how long a text string...
thanks
Code_Writer at 2007-11-11 17:34:28 >