Home > Net >  Help: c # read text according to the line
Help: c # read text according to the line

Time:09-15

For help, with c # language to create a TXT text, first to save three text box Numbers in text, such as: 23.22 51.56 91.23
Read out respectively according to the three figures again to the original three text boxes, just into the small white, see a lot of online tutorials, see a lot of bosses example, but do not understand what is going wrong, maybe all the time, please, do me a favor

CodePudding user response:

Such as written in | segmentation, inside is 23.22 51.56, 91.23 | | read out on the Split after segmentation

CodePudding user response:

Your code is unknown, here to write and read the text example
And dynamically create control example
Want to see you is how to save the data, if a data line, so, read into an array, and then loop can be assigned to control,

CodePudding user response:

String [] arr=File. ReadAllLines (" 1. TXT ");
TextBox1. Text=arr [0];
TextBox2. Text=arr [1].
TextBox3. Text=arr [2];

CodePudding user response:

 class Program 
{
The static void Main (string [] args)
{
Double num1=23.22;
Double num2=51.56;
Double num3=91.23;

//file path AppDomain. CurrentDomain. BaseDirectory for current application base directory + your file name
String path=AppDomain. CurrentDomain. BaseDirectory + "Save. TXT";
FileStream FileStream=null;
//to save the digital input above
//check whether there is the file
if (! File. The Exists (path))
{
//created if there is no
FileStream=new fileStream (path, FileMode. Create, FileAccess. Write);
}
The else
{
//if there are open
FileStream=new fileStream (path, FileMode. Open, FileAccess. Write);
}
//write data
StreamWriter StreamWriter=new StreamWriter (fileStream);
//to use, separated
StreamWriter. Write (num1 + ", "+ num2 +", "+ num3);
//remove the buffer and close the
StreamWriter. Flush ();
StreamWriter. Close ();



//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- read -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
String readData=https://bbs.csdn.net/topics/File.ReadAllText (path);
//will read data, segmentation
String [] dataArray=readData. Split (', ');

//your operating
Num1=double. Parse (dataArray [0]).
Num2=double. Parse (dataArray [1]).
Num3=double. Parse (dataArray [2]).


//according to see if you can change the above to below with the File directly class to write
Console. WriteLine (string. Join (" \ n ", dataArray));
Console.ReadLine();
}
}

CodePudding user response:

references 4 floor WWWK @ reply:
 class Program 
{
The static void Main (string [] args)
{
Double num1=23.22;
Double num2=51.56;
Double num3=91.23;

//file path AppDomain. CurrentDomain. BaseDirectory for current application base directory + your file name
String path=AppDomain. CurrentDomain. BaseDirectory + "Save. TXT";
FileStream FileStream=null;
//to save the digital input above
//check whether there is the file
if (! File. The Exists (path))
{
//created if there is no
FileStream=new fileStream (path, FileMode. Create, FileAccess. Write);
}
The else
{
//if there are open
FileStream=new fileStream (path, FileMode. Open, FileAccess. Write);
}
//write data
StreamWriter StreamWriter=new StreamWriter (fileStream);
//to use, separated
StreamWriter. Write (num1 + ", "+ num2 +", "+ num3);
//remove the buffer and close the
StreamWriter. Flush ();
StreamWriter. Close ();



//-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- read -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
String readData=https://bbs.csdn.net/topics/File.ReadAllText (path);
//will read data, segmentation
String [] dataArray=readData. Split (', ');

//your operating
Num1=double. Parse (dataArray [0]).
Num2=double. Parse (dataArray [1]).
Num3=double. Parse (dataArray [2]).


//according to see if you can change the above to below with the File directly class to write
Console. WriteLine (string. Join (" \ n ", dataArray));
Console.ReadLine();
}
}

Thank you so much, very serious and responsible to play so much code, thank you very much!
  •  Tags:  
  • C#
  • Related