473,405 Members | 2,344 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

notepad

hi,
in my notepad i have 2 rows of data seperated by spacebar. value of first row should be saved in one variable and the other in another variable. so, how to differentiate between this values as they are in the same line.
any suggestion plz....
Nov 8 '09 #1
13 3934
tlhintoq
3,525 Expert 2GB
use string.split to split the line into to elements of a string array - using the space as the divider character
Nov 8 '09 #2
hi,
how to take a value from notepad and save it in any variable.
Nov 10 '09 #3
tlhintoq
3,525 Expert 2GB
From the notepad.exe or from a text file on the hard drive?
Nov 10 '09 #4
i have a .dat file where the values are save. i want to store this values one by one in variables.
Nov 10 '09 #5
tlhintoq
3,525 Expert 2GB
MSDN on how to read a text file:
http://msdn.microsoft.com/en-us/libr...0d.aspx?ppud=4
Nov 10 '09 #6
hi,
i used the following code but getting problem with it.
wat i wanna do is to store a line from notepad having two float values seperated by Space.
private void button1_Click(object sender, EventArgs e)
{
StreamReader sw = new StreamReader("c: \\key.txt");
line = sw.ReadLine();
Console.WriteLine(line);//its showing the output
string[] variables = line.Split(' ');
float fvalue = float.Parse(variables[0]);//this line is showing error while runnig.
can u help plz..
Nov 12 '09 #7
tlhintoq
3,525 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. string[] variables = line.Split(' '); 
  2. float fvalue = float.Parse(variables[0]);//this line is showing error 
  3.  
What is the actual error?

A. This assumes that the split returned something. If the split failed to find a space then 'variables' never gets values and remains null.
B. This assumes that the first element of the array can be made into a float. Again, could return an error or at least unexpected results.
Nov 12 '09 #8
hi,
to read from a notepad i hv used the following code.
bt the problem is, it will not read the next line.
so how to read line by line.....
Expand|Select|Wrap|Line Numbers
  1. using (StreamReader sr = new StreamReader("c: \\key.txt"))
  2. {
  3.  
  4.   string s = sr.ReadLine();
  5.   //etc.
  6.   Console.WriteLine(s);//its showing the output
  7.  
  8.   string[] variables = s.Split(' ');
  9.   float fvalue = float.Parse(variables[0]);
  10.   Console.WriteLine(fvalue);
  11. }
Nov 14 '09 #9
Markus
6,050 Expert 4TB
See the examples at the MSDN docs page for this method.

You need to iterate over the file.

Mark.
Nov 14 '09 #10
hi,
to seperate two integers in a line seperated by space i used the following function:
string[] variables = s.Split(' ');
but the problem is integers are seperated by more than one space, where the above functiion gives error. Also i cant use more than one space in split.
so, can u help plzz.....
Nov 16 '09 #11
tlhintoq
3,525 Expert 2GB
Once you have the string[], trim the leading spaces..

MyArray[0] = MyArray[0].TrimStart();
Nov 16 '09 #12
Curtis Rutland
3,256 Expert 2GB
Expand|Select|Wrap|Line Numbers
  1. string input = "1   2";  //notice that there are three spaces between the two ints
  2. string[] delims = { " " };  //note that that's a single space
  3. string[] tokens = input.Split(delims, StringSplitOptions.RemoveEmptyEntries);
tokens will now hold 2 strings, with values of "1" and "2". The "StringSplitOptions.RemoveEmptyEntries" part discards empty tokens.
Nov 16 '09 #13
Curtis Rutland
3,256 Expert 2GB
I like to use sr.ReadToEnd() if it's a relatively short text file. It will read the entire file into one string variable. If you want it broken into a string[] separated by newlines, you can .Split on the Environment.NewLine value.
Nov 16 '09 #14

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: aa | last post by:
I write to a text file, and when view the resulting file in Notepad, it shows "\t" as tabs correctly, but "\n" does not break the line. Instad it shows as a square. In Dreamweaver it shows OK....
1
by: Roger | last post by:
I've got some MS-windows (XP only?) related questions; hopefully someone can give me some advise. 1) Is there some way to make notepad to become the front window when it is started from within...
4
by: Jesper | last post by:
How can I open a textfile from C# using notepad (or the user assigned application for this).
1
by: jj | last post by:
How do I programatically default the encoding of my "Notepad" into ANSI. My application uses notepad to save some text. Some of the client computers have UTF as the default encoding in their...
9
by: Sandy | last post by:
can mfc application, send text data to opened notepad file in desktop?(live transfer of data) . can anybody help
3
by: RN Das | last post by:
Hi expert, I have a small web application in C# and ASP.Net and I want to open a file in notepad when clicked on a linked button. Here is hander code when clicked on the link button. It can open...
2
by: andreas | last post by:
hi, In windows xp in the start launch menu when i put notepad "c:\test.txt" i get notepad with test.txt in it. in vb.net when i state system.diagnostics.process.start("notepad.exe" i get...
7
by: kisshug | last post by:
hi i'm working on project.in that i have 2 call notepad.exe. i want to know how to call notepad.exe from a c program in unix environment -- kisshug Message posted via ...
9
by: =?Utf-8?B?Vmlua2k=?= | last post by:
Hello Everyone, I have this code for sendKeys. This simply sends a text to the notepad. This method runs fine, but I don't see the notepad and the text entered in that notepad. Is there any way...
36
by: Don | last post by:
I wrote an app that alerts a user who attempts to open a file that the file is currently in use. It works fine except when the file is opened by Notepad. If a text file is opened, most computers...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.