|
-
Nov 5th, 2000, 04:34 PM
#1
Thread Starter
Fanatic Member
Code:
Function RetLineWord(ByVal str As String, linenum As Long, wordnum As Long) As String
Dim x&, pos&, pos2&
For x = 2 To linenum
pos = InStr(pos + 1, str, vbCrLf)
pos = pos + 1
Next x
For x = 2 To wordnum
pos = InStr(pos + 1, str, " ")
Next x
pos2 = InStr(pos + 1, str, " ")
If pos2 = 0 Then pos2 = Len(str) + 1
RetLineWord = Mid(str, pos + 1, pos2 - pos - 1)
End Function
That's the code I use but if there's a doublespace between the lines in the string I give it, it doesn't return the value! Can someone modify it to ignore doublespcaes or something!
Visual Basic 6.0
Visual C++ 5
Delphi 5

-
Nov 5th, 2000, 04:53 PM
#2
Add this as your first line of code in RetLineWord
str = Replace(str, " ", " ')
-
Nov 5th, 2000, 04:59 PM
#3
Frenzied Member
A few posts ago I learned it's a good idea to use the $ wherever you need string thingies...
like mid$,left$,right$,instr$ and so on...
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Nov 6th, 2000, 07:46 AM
#4
Thread Starter
Fanatic Member
MartinLiss
Can you explain what that does to my code! Thanx for you reply!
Visual Basic 6.0
Visual C++ 5
Delphi 5

-
Nov 6th, 2000, 08:27 AM
#5
Frenzied Member
It replaces all the double spaces ( ) with one space ( )
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Nov 6th, 2000, 09:16 AM
#6
transcendental analytic
Why don't you ask me to maintain the code first? since i know how my own code works..
Code:
Function RetLineWord(ByVal str As String, linenum As Long, wordnum As Long) As String
Dim x&, pos&, pos2&
For x = 2 To linenum
pos = InStr(pos + 1, str, vbCrLf)
pos = pos + 1
Next x
lastspace = -1
For x = 2 To wordnum
pos = InStr(pos + 1, str, " ")
If pos - lastspace <= 1 Then x = x - 1
pos2 = InStr(pos + 1, str, " ")
If pos2 - pos = 1 Then x = x - 1
Next x
If pos2 = 0 Then pos2 = Len(str) + 1
RetLineWord = Mid(str, pos + 1, pos2 - pos - 1)
End Function
Should work with any amount of blank spaces
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 6th, 2000, 09:18 AM
#7
Frenzied Member
Hey Keda/Kado/Kadi.. come over to ICQ friend
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Nov 6th, 2000, 03:55 PM
#8
Thread Starter
Fanatic Member
KedaMAN
It doesn't work!!! Try it out your self before you give it to me please.
Visual Basic 6.0
Visual C++ 5
Delphi 5

-
Nov 6th, 2000, 06:44 PM
#9
transcendental analytic
I've noticed this gets more and more complicated as i work on it, so i thought about approach it in another way. Do you need to use this for the same text over and over again? In that case, do you do it in some kind of order? Can the text change`?
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 7th, 2000, 06:35 AM
#10
Fanatic Member
Hallo,
Try this
*********************************
Dim MyIndex
Dim MyArray(3)
Dim Srchtext
Dim Position
' your text
MyArray(0) = Text1.text
MyArray(1) = Text2.text
MyArray(2) = Text3.text
MyArray(3) = Text4.text
' text to find in your text
Srchtext= Text5.text
' selection to find the string
MyIndex = filter(MyArray, Srchtext)
' Startposition srchtext
Position = Instr(1, MyIndex(0), Srchtext)
MsgBox = (" String = " & MyIndex(0))
MsgBox = ("Startposition = " & Position)
****************************************
Create a form witk 5 textboxes and a cmdbutton
put the code in the cmdbutton
Cheers
Ray
-
Nov 7th, 2000, 07:15 PM
#11
Thread Starter
Fanatic Member
Yeah, I usually get the HTMl of a page wich changes every 20 seconds, but the text barely changes, it's only like 10 words that change!
Visual Basic 6.0
Visual C++ 5
Delphi 5

Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|