Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 135,912 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 2,555 people online right now. Registration is fast and FREE... Join Now!




Read/Write Richtextbox Line by Line

 
Reply to this topicStart new topic

Read/Write Richtextbox Line by Line

cbr4rusty
18 May, 2008 - 10:45 AM
Post #1

New D.I.C Head
*

Joined: 15 Apr, 2008
Posts: 25

I currently have a program that reads text from a text file and splits it accordingly and then saves the results to another text file. How can I do this between two richtextboxes in a form? Basicaly, how can you read and write one line at a time from a richtextbox?? Thanks,

Rusty


CODE

            while ((line=objReader.ReadLine())!=null)
            {
                Array1 = line.ToString();
                textArray =line.Split('"');
                System.Collections.ArrayList fieldArray = new System.Collections.ArrayList();
                object[] arInfo1 = new object[7];
                arInfo1 = line.Split(splitter);
                
                foreach (string field in arInfo1)
                {
                    fieldArray.Add(field);
                }
                myList.Add(arInfo1[0].ToString() + '\t' + arInfo1[1].ToString() + '\t' + textArray[1].ToString() + '\t' + textArray[3].ToString() + '\t' + textArray[5].ToString()+arInfo1[6].ToString());
            }

            SaveIT();
            objReader.Close();



This post has been edited by cbr4rusty: 18 May, 2008 - 10:48 AM
User is offlineProfile CardPM
+Quote Post

zakary
RE: Read/Write Richtextbox Line By Line
19 May, 2008 - 10:56 AM
Post #2

D.I.C Regular
Group Icon

Joined: 15 Feb, 2005
Posts: 404



Thanked: 6 times
Dream Kudos: 175
My Contributions
what is myList why are you using the foreach if you are just going to do
csharp

myList.Add(arInfo1[0].ToString() + '\t' + arInfo1[1].ToString() + '\t' + textArray[1].ToString() + '\t' + textArray[3].ToString() + '\t' + textArray[5].ToString()+arInfo1[6].ToString());

User is online!Profile CardPM
+Quote Post

cbr4rusty
RE: Read/Write Richtextbox Line By Line
20 May, 2008 - 08:17 AM
Post #3

New D.I.C Head
*

Joined: 15 Apr, 2008
Posts: 25

QUOTE(cbr4rusty @ 18 May, 2008 - 11:45 AM) *

I currently have a program that reads text from a text file and splits it accordingly and then saves the results to another text file. How can I do this between two richtextboxes in a form? Basicaly, how can you read and write one line at a time from a richtextbox?? Thanks,

Rusty


CODE

            while ((line=objReader.ReadLine())!=null)
            {
                Array1 = line.ToString();
                textArray =line.Split('"');
                System.Collections.ArrayList fieldArray = new System.Collections.ArrayList();
                object[] arInfo1 = new object[7];
                arInfo1 = line.Split(splitter);
                
                foreach (string field in arInfo1)
                {
                    fieldArray.Add(field);
                }
                myList.Add(arInfo1[0].ToString() + '\t' + arInfo1[1].ToString() + '\t' + textArray[1].ToString() + '\t' + textArray[3].ToString() + '\t' + textArray[5].ToString()+arInfo1[6].ToString());
            }

            SaveIT();
            objReader.Close();




I used the while because I was reading in 1 line at a time until the end of a .txt file and splitting the line twice and then picking the parts of that split that I needed. That was an unusual circumstance, but I still would like to read one line at a time from a richtextbox. How can I do this?


User is offlineProfile CardPM
+Quote Post

zakary
RE: Read/Write Richtextbox Line By Line
20 May, 2008 - 09:07 AM
Post #4

D.I.C Regular
Group Icon

Joined: 15 Feb, 2005
Posts: 404



Thanked: 6 times
Dream Kudos: 175
My Contributions
csharp

System.Collection.ArrayList textArray = new System.Collection.ArrayList();

//reads each line
while ((line=objReader.ReadLine())!=null)
{
// adds each string to textArray using " as a splitter (string Example: Test1"Test2 Array value textArray[0] will be Test1, textArray[1] will be Test2)
textArray.AddRange(line.Split('"'));
}

User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 07:48AM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month