I'm currently doing console application. How do I display S.1.1.004 into the console?
CREATE from S.1.1.001 to S.1.1.002 on Monday, 7th of May, 2019 07:20:44
CREATE from S.1.1.002 to S.1.1.003 on Tuessday, 23rd of March, 2018 10:01:22
CREATE from S.1.1.003 to S.1.1.004 on Wednesday, 4th of February, 2019 5:42:45
static void Main(string args)
TextReader st = new StreamReader("C://test.txt");
int NumOfLines = 3;
string ListLines = new string[NumOfLines];
for (int i = 0; i < NumOfLines; i++)
ListLines[i] = st.ReadLine();
Assuming that you want to show a specific part from the last line in the file, you can do it very easily.
There are two basic ways: use Substring, which extracts a specific portion from a string (good if your line format is static and never changes) or use a Regular Expression (good if the data moves around, changes position from line to line).
First, read all the lines:
phil.o has given you the documentation, but if you look at your line text, the section you want starts at index 25 (starting form zero, remember) and is 9 characters long. So those are the numbers you feed into substring to specific exactly which chunk of text you want to extract.
A Regex will do fine, but they can be complicated and difficult to understand (and worse to modify), so it you can use a "fixed position" extraction for now, that's the best place to start.
Sent from my Amstrad PC 1640 Never throw anything away, Griff
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
AntiTwitter: @DalekDave is now a follower!
The Master said, 'Am I indeed possessed of knowledge? I am not knowing. But if a mean person, who appears quite empty-like, ask anything of me, I set it forth from one end to the other, and exhaust it.'
― Confucian Analects
The ReadLines and ReadAllLines methods differ as follows: When you use ReadLines, you can start enumerating the collection of strings before the whole collection is returned; when you use ReadAllLines, you must wait for the whole array of strings be returned before you can access the array. Therefore, when you are working with very large files, ReadLines can be more efficient.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Maybe he/she/them/they doesn't have a favorite search enchine.
".45 ACP - because shooting twice is just silly" - JSOP, 2010 ----- You can never have too much ammo - unless you're swimming, or on fire. - JSOP, 2010 ----- When you pry the gun from my cold dead hands, be careful - the barrel will be very hot. - JSOP, 2013
Then you need to go back to the original message and edit it with proper details of what you are looking for. No one guess from "I need code" exactly what problem you are trying to solve. Keep in mind that we cannot see your screen, or know anything about your project, so the only details we can work on is what you tell us.
I am writing a tiny app which will be triggered in GPO by a user logoff. The app simply checks that the user has done some required housework. Can anyone show me how to interrupt the logoff (and remain logged on) depending on the answer?
Last Visit: 16-Oct-19 21:41 Last Update: 16-Oct-19 21:41