Wrox Programmer Forums
|
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 7th, 2005, 03:15 PM
Authorized User
 
Join Date: Aug 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default Editing text in a richtextbox

I have created a program that opens a text file into a RichTextBox1. Now that I have this accomplished I would like to go through the list of text and clean it up. What I have is a list of stats for various people who play an online game. The problem is that there is also stats that are embedded for computer generated players. These are identified throughout the text as having [BOT] at the end of the screen name. Each line of text contains the screen name and their stats. How can I go through the text in the RichTextBox1 and search for [BOT] and remove this line of text?



Jeff Armstrong
Sr. Systems Mgr
SBC Services, Inc.
__________________
Jeff Armstrong
Sr. Systems Mgr
SBC Services, Inc.
 
Old March 7th, 2005, 04:01 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Put the contents of the textbox into a string, manipulate the string, then replace the box’s contents with the contents of the manipulated string.

You are going to have to create a routine that knows how to “read” (so to speak).
 
Old March 7th, 2005, 05:16 PM
Authorized User
 
Join Date: Aug 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I guess all I really need at this point is to search for [BOT] within a string. If it has it then delete the string otherwise move on. Is there a way that I can search the string and so some type of compare?

Jeff Armstrong
Sr. Systems Mgr
SBC Services, Inc.
 
Old March 7th, 2005, 05:52 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

You can use the .IndexOf("Pattern") method of a string to find the 1[u]st</u> occurence of a pattern within a string.
You can use .IndexOf("pattern", n) to find the next occurence of a pattern within a string, starting at character #n.

You can use .LastIndexOf("pattern") to find the last occurence of a pattern within a string.
(.LastIndexOf() can also accept a 2nd argument, just like IndexOf())
 
Old March 8th, 2005, 05:15 PM
Authorized User
 
Join Date: Aug 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I got the filter to work. Thanks for the tip. I decided to go with a ListBox rather than a RichTextBox. It was easier to implement in real time and faster. My only problem now is saving the data within the ListBox. How can I save the data in the ListBox to a text file?

Jeff Armstrong
Sr. Systems Mgr
SBC Services, Inc.
 
Old March 9th, 2005, 04:10 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

.NET has a variety of functions for streaming to a text file. (I believe they are in System.IO...)

Though (I believe) you can directly save the contents of a richtext box, you have to handle the file yourself with a listbox.

It is pretty easy though. You open a stream object having set it to append or replace, then one-line-at-a-time (with .WriteLine) or character-by-character (with .Write) put your data into the file, then close it.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Selecting Text When Editing Datagrid elygp ASP.NET 1.0 and 1.1 Professional 1 May 29th, 2007 04:58 PM
Editing a Text File mh VB.NET 1 December 8th, 2005 02:37 AM
Deleting text from a RichTextBox wslyhbb C# 0 October 29th, 2005 08:00 PM
.NET Text / HTML editing problem clickco General .NET 3 May 12th, 2004 02:47 PM
#region text in RichTextBox? mfourre C# 1 August 7th, 2003 12:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.