Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find/Replace in RichTextBox, Urgent!

Status
Not open for further replies.

jmlady

Programmer
Nov 20, 2003
19
0
0
US
Hey, I currently have a RTB1 field, and I'm trying to make a FOR loop to seperate words..

The files that are uploaded into the RTB field, are .txt files that have words: aaa bbb ccc ddd ...
and i'm trying to take each word insert a linebreak at the space. However, when I get to the end of the document, it keeps adding Spaces and continues until the program freezes.

My Code I was using for it was..

RTB1.Find(strSpace)
RTB1.selRTF = CharRet + LineFeed

Then, when I tried to use break characters, such as a Period (.), it would initially search for the Period (.) and end the word-parse.

Any help would be greatly appreciated!

Thanks
 
Replace each space with a linebreak...

RTB1.Text = Replace(RTB1.Text, Chr(32), vbNewLine)
 
Wow, Thanks a LOT!
I guess I was going about it all wrong. Well, again, Thanks :)
 
Note, however, that LPlate's solution will lose cause any formatting that you have applied to the text (eg color, size, etc) to be lost.
 
Got a solution strongm? I tried ..

RTB1.TextRtf = Replace(RTB1.TextRtf,Chr(32),Chr(13))

also..
RTB1.TextRtf = Replace(RTB1.TextRtf,Chr(32),vbNewLine)

both retain rtf formatting and remove the space but the text doesnt break to the next line
 
well i managed to do it but it's really dodgy the way i did it so i don't recommend it, but if you cant find out any better way then at least it's something to think about..

first have a richtextbox and a textbox. copy the contents of the richtextbox (rtb1.textrtf) into the textbox (text1.text) so that all the formatting commands and text is in the textbox

then run your code on text1.text but excluding all the formatting commands somehow (could be tricky) before copying the newly formatted text1.text into rtb1.textrtf

as i said, pretty crappy way of doing it, but i couldnt get it to work using the replace command either.
 
Thanks a lot guys...it's quite alright, there were no special formats I had on the text. I'm teaching myself Visual Basic, and am just trying to get a real feel in a real time environment with an actual program idea...

But thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top