Click here to Skip to main content
15,890,185 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am reading a large text file in c# using stream reader. I need to split the string values after say 500 characters as my file could contain around 1000 characters and thereafter join those values while retrieving. Saving and retrieval is being to a windows store there.

What I have tried:

Core Code is as below:
using (StreamReader sr = new StreamReader(@"D:\test.txt"))
               {
                   // Read the stream to a string, and write the string to the console.
                   string line = sr.ReadToEnd();
Posted
Updated 4-Jun-18 0:27am

Use Streamreader.Read[^] and you can specify exactly how many characters to read at a time.
 
Share this answer
 
Comments
ranio 4-Jun-18 5:37am    
Below is the Content:
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2.0.22 (MingW32)

mQENBFodV6IBCADbWOiM9wd1v023MSuJhqPrbcJzkBewR6umUOujo+X5mA4E4YUs
o7OzwHjsF4CA5e7/eOuooIwcJ/zCthbkUBEszi1o991eD4zTLM2jKUXKMPmvlLqs
zdISDxBJSWNnaz6taW55NPYL+BMS7Be9/wuChMY5p8HS3SQXBFjWqtZ6SkHL33Gk
QtQVjZD8eh3OJ+tXXP5cv6taUgrTsxzzI2F+j8+jwu+0guU66o1d3Q8IoH4C8yCH
xu2szuZmzQst19MF64Z5w7DGl0Y1KEbL0sgxvQ0Wmoxcqycit+78eeq5590/6l5R
7+ScP/koDeACBdaq/UJspGc3nnMfZwRQTNgZABEBAAG0IENCX1dTSSA8bmFuZGh1
LnBrQG5lc3Rncm91cC5uZXQ+iQE5BBMBAgAjBQJaHVeiAhsPBwsJCAcDAgEGFQgC
CQoLBBYCAwECHgECF4AACgkQ0/gIj6+qv9537ggAwkQ35yRYkCxJ3AdnEMxfCLpn
1Z8/yUSiawc4t81mIGD1WPDJDVbnPApI8fhqrHxHWyFgA/6U7z62wWV71UC2Ww81
NYWJGvLDkrgth7TdGd9ngBy447AgzsmcaJ4a/GAsFNgWnyRMhzaCs1Hmz51tjlSY
5txuMBO8avIBPQ5E4ULz9pAWjkQ72le+dXJSY7b1qNxkIvwk0GNkk/Uvi4YdQ9Lf
pRUXaua8VBnXzXuqY+rcA5n2d4PZDBRldgEoRwEqAciU4wonxFIKY7jdfnCLWWtf
+92Nxd41tsn3nj6eBnKcE6+2HNcCV9lxn879hWMD+34el7IuCMM8JIyyshp3mg==
=6CSY
-----END PGP PUBLIC KEY BLOCK-----
OriginalGriff 4-Jun-18 5:45am    
And? What do you want me to do with it?
ranio[^] wrote:

Below is the Content:
-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2.0.22 (MingW32)

mQENBFodV6IBCADbWOiM9wd1v023MSuJhqPrbcJzkBewR6umUOujo+X5mA4E4YUs
o7OzwHjsF4CA5e7/eOuooIwcJ/zCthbkUBEszi1o991eD4zTLM2jKUXKMPmvlLqs
zdISDxBJSWNnaz6taW55NPYL+BMS7Be9/wuChMY5p8HS3SQXBFjWqtZ6SkHL33Gk
QtQVjZD8eh3OJ+tXXP5cv6taUgrTsxzzI2F+j8+jwu+0guU66o1d3Q8IoH4C8yCH
xu2szuZmzQst19MF64Z5w7DGl0Y1KEbL0sgxvQ0Wmoxcqycit+78eeq5590/6l5R
7+ScP/koDeACBdaq/UJspGc3nnMfZwRQTNgZABEBAAG0IENCX1dTSSA8bmFuZGh1
LnBrQG5lc3Rncm91cC5uZXQ+iQE5BBMBAgAjBQJaHVeiAhsPBwsJCAcDAgEGFQgC
CQoLBBYCAwECHgECF4AACgkQ0/gIj6+qv9537ggAwkQ35yRYkCxJ3AdnEMxfCLpn
1Z8/yUSiawc4t81mIGD1WPDJDVbnPApI8fhqrHxHWyFgA/6U7z62wWV71UC2Ww81
NYWJGvLDkrgth7TdGd9ngBy447AgzsmcaJ4a/GAsFNgWnyRMhzaCs1Hmz51tjlSY
5txuMBO8avIBPQ5E4ULz9pAWjkQ72le+dXJSY7b1qNxkIvwk0GNkk/Uvi4YdQ9Lf
pRUXaua8VBnXzXuqY+rcA5n2d4PZDBRldgEoRwEqAciU4wonxFIKY7jdfnCLWWtf
+92Nxd41tsn3nj6eBnKcE6+2HNcCV9lxn879hWMD+34el7IuCMM8JIyyshp3mg==
=6CSY
-----END PGP PUBLIC KEY BLOCK-----


Your text file is protected by GnuPG software. You have to decrypt it to be able to read its content.
Check this: PGP Encryption with C#[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900