-
Dec 4th, 2008, 06:37 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] RTF search and get
Hi guys,
Wanted to ask...
im using the find function in rtf, and when the text is found i get the number of the postion...now i would like to know how to get the text from that position + the next 10 chars?
im pretty lame with that selstart, sellength thing
Thanks for helping me out.
-
Dec 4th, 2008, 06:49 AM
#2
Re: RTF search and get
Are you searching for specific words that, when found, you want to highlight?
-
Dec 4th, 2008, 06:57 AM
#3
Thread Starter
Hyperactive Member
Re: RTF search and get
Well...i dont need to highlight them...i just need to extract them out of that rtf box and only what i need to trasnfer to another place....
Thanks for helping me out.
-
Dec 4th, 2008, 01:39 PM
#4
Re: RTF search and get
Code:
With rtb
.SelStart = .Find("Texttofind")' Change to the word to find
.SelLength = 10
MsgBox .SelText
text1 = .Seltext
.SelText = "" 'delete the text ?
End With
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders
-
Feb 17th, 2009, 10:42 AM
#5
Thread Starter
Hyperactive Member
Re: RTF search and get
Originally Posted by isnoend07
Code:
With rtb
.SelStart = .Find("Texttofind")' Change to the word to find
.SelLength = 10
MsgBox .SelText
text1 = .Seltext
.SelText = "" 'delete the text ?
End With
can it be changed so it will get the second results not the first one??
Thanks for the code!!
Thanks for helping me out.
-
Feb 17th, 2009, 01:04 PM
#6
Re: RTF search and get
Do you mean, you want to ignore the first "find"?
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Feb 17th, 2009, 01:21 PM
#7
Re: RTF search and get
Delete the 2nd occurance of string
I got it
With rtb
.SelStart = .Find(Texttofind) ' Change to the word to find
.SelLength = Len(Texttofind)
.SelStart = .Find(Texttofind, .SelStart + .SelLength)
.SelLength = Len(Texttofind)
.SelText = ""
End With
Last edited by isnoend07; Feb 17th, 2009 at 01:29 PM.
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders
-
Feb 17th, 2009, 02:39 PM
#8
Re: RTF search and get
This will not only get the 2nd but whichever occurance you want...
http://www.vbforums.com/showpost.php...35&postcount=3
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Feb 17th, 2009, 07:33 PM
#9
Thread Starter
Hyperactive Member
Re: RTF search and get
Originally Posted by koolsid
Yeah i want to find only the second occurence...
ill try that guys....
sorry i was not home the entire day so i could reply...not its 2 am almost...im gogin to sleep, ill try that tomorrow
thanks alot!!!!!!!!!!
Thanks for helping me out.
-
Feb 18th, 2009, 05:11 AM
#10
Thread Starter
Hyperactive Member
Re: RTF search and get
It worked out great..
but would it be possbile to start from where i found a specific word and to take the string until i get to lets say this char ";" ?
hmmm
thanks for the help man!
Thanks for helping me out.
-
Feb 18th, 2009, 09:02 AM
#11
Re: RTF search and get
would it be possbile to start from where i found a specific word and to take the string until i get to lets say this char ";" ?
yes it is possible.. you will have to amend the function a bit... let me see what can i do I am going out with my wife in few minutes and will be back quite late... but i will post the codes the moment i get the first chance...
Edit
Okay, apparently we didn't go .
Here it is....
Create a Form, Commandbutton and 1 RTB. Just Run it...
This example finds the third occurance of "Sid" and then finds the first occurance of ";" and then gives you the string in between...
I am sure that this code can further be shortened. I have commented the code so you won't have trouble understanding what I did
Hope this helps...
Code:
Option Explicit
Dim Ret
Dim FoundStrpos As Long, FoundStrLen As Long, CurInitStart As Long
Dim CurInitLen As Long, lngCount As Long, lColor As Long, pos As Long
Dim StrLen As String, MyArray() As String, TempString As String
Private Sub Form_Load()
'Getting sample text
RichTextBox1.Text = " I was on my way to meet Sid. Sid was not available. " _
& "His Friend informed that Sid is out of town ; I left after that..."
End Sub
Private Sub Command1_Click()
'-- USAGE
'-- FindText(RichTextBox1, Search String, nth occurance, String to search after that)
'-- Will find 3rd occurance of "Sid" and Then find first occurance of Semi-Colon
'-- if found, will give you the middle string "is out of town" in this case
Ret = FindText(RichTextBox1, "Sid", 3, ";")
End Sub
Private Function FindText(Rich As RichTextBox, sFindString As String, Numb As Integer, StrSearch As String)
lColor = vbGreen '-- Color for "Sid"
'-- Save the cursor's current length and location
CurInitStart = Rich.SelStart
CurInitLen = Rich.SelLength
'-- Length of the string to find
FoundStrLen = Len(sFindString)
'-- Find the first match of "Sid"
FoundStrpos = Rich.Find(sFindString, 0, , rtfNoHighlight)
If FoundStrpos > -1 Then
Rich.SelStart = FoundStrpos
Rich.SelLength = FoundStrLen
lngCount = lngCount + 1
End If
While FoundStrpos > -1
'-- Exception -- if you want to JUST find the first occurance
If Numb = 1 Then
'-- if found "Sid" then color GREEN
Rich.SelColor = lColor
'-- Get in between string
Call InBetweenString(Rich)
'-- Assign any number below -1 to get out of loop
FoundStrpos = -2
ElseIf lngCount > 0 And lngCount < Numb Then
'Attempt to find the next match for "Sid"
FoundStrpos = Rich.Find(sFindString, _
FoundStrpos + FoundStrLen, , rtfNoHighlight)
Rich.SelStart = FoundStrpos
Rich.SelLength = FoundStrLen
'-- if found
If lngCount = (Numb - 1) Then
'-- Color Search String "Sid" in GREEN
Rich.SelColor = lColor
'-- Get in between string
Call InBetweenString(Rich)
End If
'-- Increment Count
lngCount = lngCount + 1
Else
'-- Assign any number below -1 to get out of loop
FoundStrpos = -2
End If
Wend
'-- Restore the cursor to its original status
Rich.SelStart = CurInitStart
Rich.SelLength = CurInitLen
End Function
Sub InBetweenString(Rich As RichTextBox)
Dim StrSearch As String, sFindString As String
StrLen = FoundStrpos + FoundStrLen
Rich.SelStart = StrLen
StrLen = StrLen - 1
Rich.SelLength = Len(Mid(Rich.Text, StrLen, Len(Trim(Rich.Text)) - StrLen))
'-- Get the entire RTB string after the occurance of "Sid"
TempString = Rich.SelText
'-- Search for ";"
pos = InStr(1, TempString, ";")
'-- If ";" is found
If pos <> 0 Then
MyArray = Split(TempString, ";")
'-- Display the String
MsgBox MyArray(0)
Else
'-- Inform user that ";" doesn't exist
MsgBox "There is no occurance of " & _
"'" & StrSearch & "'" & _
" in the RTB after " & _
"'" & sFindString & "'"
End If
End Sub
Last edited by Siddharth Rout; Feb 18th, 2009 at 10:22 AM.
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Feb 18th, 2009, 09:41 AM
#12
Thread Starter
Hyperactive Member
Re: RTF search and get
thank you!!!!
see ya later then!
bye
Thanks for helping me out.
-
Feb 18th, 2009, 10:26 AM
#13
Re: RTF search and get
Updated the code in post 11
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread "Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
-
Feb 18th, 2009, 01:02 PM
#14
Thread Starter
Hyperactive Member
Re: RTF search and get
Great code m8!
Great job!
It works perfectly!!!!!!!!!!!!!
RATING you!
Thanks for helping me out.
-
Feb 19th, 2009, 09:01 AM
#15
Thread Starter
Hyperactive Member
Re: [RESOLVED] RTF search and get
It works fine but when i do this:
Code:
p1 = FindText(txtLoginW, "TEXT1", 2, ";")
p2 = FindText(txtLoginW, "TEXT"", 2, ";")
p3= FindText(txtLoginW, "TEXT3", 2, ";")
I get only the first result from p1.....from MyArray(0)
It would be nice to get the found data on P1...
Can i do that somehow?
Thanks for the help m8!
Thanks for helping me out.
-
Feb 19th, 2009, 10:05 AM
#16
Thread Starter
Hyperactive Member
Re: [RESOLVED] RTF search and get
Ok what i did is :
1.Put this at the end of the FindText function:
CurInitLen = 0
lngCount = 0
pos = 0
2. at the end of the FindText :
findtext = myarray(0)
that's it
Cheers
Thanks for helping me out.
-
Feb 19th, 2009, 11:44 AM
#17
Re: [RESOLVED] RTF search and get
Originally Posted by batori
It works fine but when i do this:
Code:
p1 = FindText(txtLoginW, "TEXT1", 2, ";")
p2 = FindText(txtLoginW, "TEXT"", 2, ";")
p3= FindText(txtLoginW, "TEXT3", 2, ";")
I get only the first result from p1.....from MyArray(0)
It would be nice to get the found data on P1...
Can i do that somehow?
Thanks for the help m8!
this line has a double quote: p2 = FindText(txtLoginW, "TEXT"", 2, ";")
should this be TEXT2 ?"TEXT""
Waiting for a full featured smart phone with out marrying a provider
Go Android
Go raiders
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
|