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....
13 3934
use string.split to split the line into to elements of a string array - using the space as the divider character
hi,
how to take a value from notepad and save it in any variable.
From the notepad.exe or from a text file on the hard drive?
i have a .dat file where the values are save. i want to store this values one by one in variables.
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..
- string[] variables = line.Split(' ');
-
float fvalue = float.Parse(variables[0]);//this line is showing error
-
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.
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..... -
using (StreamReader sr = new StreamReader("c: \\key.txt"))
-
{
-
-
string s = sr.ReadLine();
-
//etc.
-
Console.WriteLine(s);//its showing the output
-
-
string[] variables = s.Split(' ');
-
float fvalue = float.Parse(variables[0]);
-
Console.WriteLine(fvalue);
-
}
See the examples at the MSDN docs page for this method.
You need to iterate over the file.
Mark.
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.....
Once you have the string[], trim the leading spaces..
MyArray[0] = MyArray[0].TrimStart();
- string input = "1 2"; //notice that there are three spaces between the two ints
-
string[] delims = { " " }; //note that that's a single space
-
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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....
|
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...
|
by: Jesper |
last post by:
How can I open a textfile from C# using notepad (or the
user assigned application for this).
|
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...
|
by: Sandy |
last post by:
can mfc application, send text data to opened notepad file in desktop?(live
transfer of data) . can anybody help
|
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...
|
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...
|
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 ...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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...
|
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,...
|
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...
|
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,...
| |