|
Your loop is writing each line to console, then writing the last line to your StreamWriter. Without a better description of the problem, I'd say initialize your StreamWriter before the loop and write to it instead of the Console.
Then again, I can't tell for sure what you're actually trying to do.
Visit BoneSoft.com for code generation tools (XML & XSD -> C#, VB, etc...) and some free developer tools as well.
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
class TextFile
{
public static void Main(string[] args)
{
string inFile;
string writing;
Console.WriteLine("Filename input");
Console.WriteLine("Sample: d:\\filename.LOG");
inFile = Convert.ToString(Console.ReadLine());
StreamReader sr = File.OpenText(inFile);
writing = sr.ReadLine();
string onEk = " Frequencies -- ";
int i = 1;
string[] parts = null;
StreamWriter sw = new StreamWriter(@"C:\filename.LOG");
while (writing != null)
{
if (writing.StartsWith(onEk))
{
string transient = writing.Replace(onEk, "");
parts = transient.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
//Console.WriteLine(string.Format("{0}\n{1}\n{2}", parts[0], parts[1], parts[2]));
//i++;
sw.WriteLine(string.Format("{0}\n{1}\n{2}", parts[0], parts[1], parts[2]));
i++;
sw.Flush();
}
writing = sr.ReadLine();
}
Console.ReadLine();
sr.Close();
sw.Close();
}
}
called file contents:
Frequencies -- 1093.5623 1094.7121
Red. masses -- 6.4909 1.3756
Frc consts -- 4.5735 0.9713
Frequencies -- 0.0002 0.0400
Raman Activ -- 0.0000 0.0000
Depolar (P) -- 0.7162 0.6260
Frequencies -- 0.8346 0.7700
output data:
1093.5623 1094.7121 0.0002 0.0400 0.8346 0.7700
THANKS for reply
Finally It is writing to FILE all the line but as a line. morever there is square-zero between each two number.how can we do only one column them?
|
|
|
|
|
Problem SOLVED.BoneSoft thank you very very much :
Final CODE
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
class TextFile
{
public static void Main(string[] args)
{
string inFile;
string writing;
Console.WriteLine("Filename input");
Console.WriteLine("Sample: d:\\filename.LOG");
inFile = Convert.ToString(Console.ReadLine());
StreamReader sr = File.OpenText(inFile);
writing = sr.ReadLine();
string onEk = " Frequencies -- ";
int i = 1;
string[] parts = null;
StreamWriter sw = new StreamWriter(@"C:\filename.LOG");
while (writing != null)
{
if (writing.StartsWith(onEk))
{
string transient = writing.Replace(onEk, "");
parts = transient.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
//Console.WriteLine(string.Format("{0}\n{1}\n{2}", parts[0], parts[1], parts[2]));
//i++;
//sw.WriteLine(string.Format("{0}\n{1}\n{2}", parts[0], parts[1], parts[2]));
sw.WriteLine(string.Format(parts[0]));
sw.WriteLine(string.Format(parts[1]));
sw.WriteLine(string.Format(parts[2]));
i++;
sw.Flush();
}
writing = sr.ReadLine();
}
Console.ReadLine();
sr.Close();
sw.Close();
}
}
wanted output data:
1093.5623
1094.7121
0.0002
0.0400
0.8346
0.7700
I am happy
|
|
|
|
|
In the future, you can use "\r\n" instead of just "\n".
Visit BoneSoft.com for code generation tools (XML & XSD -> C#, VB, etc...) and some free developer tools as well.
|
|
|
|
|
this is the code
DataTable dt;
protected void Wizard1_NextButtonClick(object sender, WizardNavigationEventArgs e)
{
wsChattels.WebService ws = new wsChattels.WebService();
ws.Credentials = System.Net.CredentialCache.DefaultCredentials;
try
{
dt = this.GetCustomer();
DataRow dr = dt.NewRow();
dr[0] = txtUsername.Text;
dr[1] = txtfirstname.Text;
dr[2] = txtlastname.Text;
dr[3] = txtmobile.Text;
dr[4] = txttelephone.Text;
dr[5] = txtEmail.Text;
dt.Rows.Add(dr);
}
catch (Exception ie)
{
throw ie;
}
}
protected void Wizard1_FinishButtonClick(object sender, WizardNavigationEventArgs e)
{
wsChattels.WebService ws = new wsChattels.WebService();
ws.Credentials = System.Net.CredentialCache.DefaultCredentials;
int i = dt.Rows.Count;
try
{
DataTable dtProperty = this.GetProperty();
DataRow drProperty = dtProperty.NewRow();
int buyingtype = Convert.ToInt32(this.ddlBuyingType.SelectedValue);
int propertytype = Convert.ToInt32(this.ddlPropertyType.SelectedValue);
int townid = Convert.ToInt32(this.ddlTown.SelectedValue);
drProperty[0] = buyingtype;
drProperty[1] = txtPropertyName.Text;
drProperty[2] = propertytype;
drProperty[3] = townid;
drProperty[4] = txtPrice.Text;
drProperty[5] = txtDescription.Text;
dtProperty.Rows.Add(drProperty);
foreach (DataRow dr in dt.Rows)
{
ws.AddNewSubmitClient(dr[0].ToString(), dr[1].ToString(), dr[2].ToString(), dr[3].ToString(), dr[4].ToString(), dr[5].ToString());
}
}
can anyone help me pls
|
|
|
|
|
I´m making a C# spelling test.
I´m having trouble with the grading process.
My idea is not having a spell check but rather compare two texts and count the errors. One text is hidden of course.
How would you think the easiest way to do this would be?
|
|
|
|
|
Out of curiosity, how will the user know what words she is supposed to spell for the test?
|
|
|
|
|
LMAO
Spelling Test, enter the correct spelling for the following words:
1) hyperbole
led mike
|
|
|
|
|
Oh, I forgot to mention. A mp3 file will be played where the text is read out.
But do you have any ideas on what the easiest way to do this would be?
|
|
|
|
|
Use character arrays for the strings and check each character. You need to decide if you give points for a correct word with different length and handle that scenario.
correct answer: hyperbole
user enetered: hyperboole
The lengths are different so a straight char comparison won't work. You should probably search the rest of the entered text for the char.
Good luck as there's plenty of ways you can give points.
|
|
|
|
|
why would you do a char by char comparison instead of just comparing the strings?
I misunderstood... I didn't realize this was more than a "right" or "wrong" problem...
<br />
if (string.Equals(sUserAnswer, sCorrectAnswer, StringComparison.OrdinalIgnoreCase))<br />
{<br />
}<br />
else<br />
{<br />
}<br />
I suggest that you create an XML file that specifies the word to spell along with the location of the media file that corresponds to the spoken word. Something like:
<words>
<word media="C:\Words\Hello.mp3">Hello</word>
<word media="C:\Words\Hyperbole.mp3">Hyperbole</word>
...
</words>
The application should then allow you to load the XML file that corresponds to the test you want to take.
modified on Thursday, April 17, 2008 4:37 PM
|
|
|
|
|
My idea was to have a test where the student or who ever is taking the test, would listen to a mp3 file. I was thinking about having the mp3 played on an external player.
It is a block of text, so I´m thinking is it possible to compare two sentences?
Could any of you guys show me some example of how this is done?
modified on Thursday, April 17, 2008 3:49 PM
|
|
|
|
|
Of course it's possible to compare two sentences. A sentence is just a string, right? But how will comparing sentences solve your problem? The user will be spelling words, not sentences, right? Don't start solving the wrong problem!
I think you need to take a step back and think about what you're trying to do. Spend some time with paper and pencil and sketch out some use-cases. This will help you conceptualize the problem. For example, what do you want the user experience to be? Pretend that you are going to take a spelling test. How would you expect the application to behave? Once you jot down the basic use case, start considering edge cases. For example, what if I decide to change my answer after I've already typed it in? Will the words be checked immediately after they are entered? Or will they be checked all at once when the user "finishes" the test? If the audio is not associated with the words in your program, how will you know which word the user was trying to spell? What if the user spells the words in the wrong order (the application expected them to spell "Hello" then "Hyperbole" but they spelled "Hyperbole" then "Hello")?
Going through the use cases will help you conceptualize the problem and prevent you from being short-sighted in your solution.
Good luck!
|
|
|
|
|
I have some use cases.
How would you do this?
|
|
|
|
|
Show me one of your use-cases and I'll be glad to help you think through this.
|
|
|
|
|
I'd use the Levensthtein distance[^] to count the number of different characters between the correct and given answer.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi,
seems to me you need to:
- split both texts into words (split on spaces and puctuation);
- match the words (resync when a word is missing in one of the texts);
- count the differences (each pair of matching words that are not identical count as one mistake).
Why match words: the sucker under test may connect two words, split a word in two,
just forget one, etc.
remaining problems:
- punctuation: do you check those chars too? can you hear the difference between
say a semi-colon and a period?
- capitals: are the rules strict in your language? is it the same for the first letter
following a semi-colon and a period?
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
Hi everyone,
I have created two applications which both do similar jobs but i want to merge them together into one. I can't extract the forms from one and put them into the other because one of them was created in visual basic. I have tried to get the exe fle from the vb project into the c# project and have succeded in putting it into the resources folder. Problem is running it. HOW????
Please help.
thanks,
Ashley Staggs
|
|
|
|
|
Are you trying to make the two applications behave like a single application? You can't simply "combine" two applications like that...
Are you simply wanting to reuse some of the functionality from the VB application? If so, what you really want to do is figure out what bits of functionality you want from the VB project and convert those pieces into user controls. You can then reference the VB user controls in you C# project.
|
|
|
|
|
Basically i want the c# app to load the exe file from the resources folder
|
|
|
|
|
You can get the C# application to "start" the VB application, but the VB application will still be a separate application. It will still have its own UI and it will run in its own process -- just as it would if the user started it manually.
Are you really simply trying to start the other application programatically? Or are you trying to get the two applications to behave as a single app?
|
|
|
|
|
A single app. The vb app has been created in the 2008 edition whereas the c# is 2005
|
|
|
|
|
You can't add an executable as a resource and simply have another application "run" it as though it was part of the "host" application. What you want is a library (dll) not an executable. This means you will need to figure out what parts of the VB application you would like to re-use and re-create those pieces as classes or user-controls in a dynamic link library. Once you have those components in a library, you can add a reference to that assembly and start using the components.
|
|
|
|
|
if you have two .NET apps you can turn one (or both) of them into a DLL, and make
the remaining one (or a new one) the master controlling the other (or both).
The one (or two) that demotes to a DLL looses its static main function (C#) or the
VB equivalent, so it basically becomes a class library; to call it, instantiate
its main form and show it (as the static main does in a regular C# Windows app).
You must do it with a single version of .NET (hence the same Visual Studio);
having a non-Express edition probably makes it much easier, since now you can load
all relevant projects in a single IDE.
With VS2008VB Express + VS2008CS Express, you should also be able to do it, have one
create the DLL, then add that to the references of the other.
Luc Pattyn [Forum Guidelines] [My Articles]
This month's tips:
- before you ask a question here, search CodeProject, then Google;
- the quality and detail of your question reflects on the effectiveness of the help you are likely to get;
- use PRE tags to preserve formatting when showing multi-line code snippets.
|
|
|
|
|
how do i change the vb project into a dll and then in th c# app how do i get it to start.
|
|
|
|