|
thanks for replies
t1.txt is:
11
22
33
44
55
.
.
how can I get x value? x=a(line's 1 value)+b(line's 3 value)+c(line 5)that is c must 99
using System;<br />
using System.IO;<br />
<br />
class MainClass<br />
{<br />
public static void Main(string[] args)<br />
{<br />
try<br />
{<br />
FileStream fs = new FileStream("c:\\t1.txt", FileMode.Open);<br />
StreamReader sr = new StreamReader(fs);<br />
<br />
string line = "";<br />
<br />
int lineNo = 0;<br />
do<br />
{<br />
line = sr.ReadLine();<br />
if (line != null)<br />
{<br />
Console.WriteLine("{0}: {1}", lineNo, line);<br />
lineNo++;<br />
x=a+b+c;-------->values=?<br />
}<br />
} while (line != null);<br />
}<br />
catch (Exception e)<br />
{<br />
Console.WriteLine("Exception in ShowFile: {0}", e);<br />
}<br />
}<br />
}
|
|
|
|
|
First of all: use the pre tag, it's better than the code tag.
Secondly it is not as tough as you think. Just use common sense for this question:
You are using the do while construction, but if I where you, I should use the while function or for function.
List<string> lines = new List<string>();
String line;
while((line = sr.ReadLine()) != null)
{
lines.Add(line);
}
try
{
int numberOne = Int32.Parse(lines[0]);
int numberThree = Int32.Parse(lines[2]);
int numberFive = Int32.Parse(lines[4]);
int x = numberOne + numberThree + numberFive;
}
catch {}
</string></string>
You could use the TryParse method, but you can also use the try catch block.
Good luck!
|
|
|
|
|
wonderful
thank you very much
|
|
|
|
|
Hi!
I have a world map in my GUI and I want the countries to highlight when mouse hovers over a country. Something like this http://www.netzgesta.de/mapper/
Is this possible to do this with c# at all?
I have read about the Imagemap controller with which it is possible to do polygon hotspots, but I'm not sure this is exactly what I need. It can't change anything within the coordinates of the polygon when mouse hovers over the hotspots.
Can someone give me a clue what to do?
|
|
|
|
|
|
LMAO! Just posted the exact same link
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Yes, but it doesn't have that hover effect.
|
|
|
|
|
So use it as a base and program the hover effect yourself.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
There's an article here[^] that might help
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
hello,
I would stock a list of string, i make this
<br />
string[] TableauString;<br />
<br />
TableauString[tt]= (nom.Trim() + ";" + prenom.Trim() + ";" + adresse1.Trim() + ";" + cp.Trim() + ";" + ville.Trim() + resultat3.Trim() + resultat2.Trim());<br />
tt++;<br />
<br />
there are exception : the referce is not instance of obkect, help me please to resolve this problem, thank you verry mutch
|
|
|
|
|
The exception occurs because you don't allocate any memory for the string array. Try something like this:
string[] TableauString = new string[10];
Here i allocate a memory for 10 elements. This is only an example. You have to specify correct size for the array depending on your needs.
|
|
|
|
|
If i don't know the size of my elements?? thank you verry mutch
|
|
|
|
|
You can use the code as shown bellow just replace
"The Size" with an int number
TestArray= Array.CreateInstance(typeof(String),"The Size");
this will create a array based on the size that you want
hopes this helps
|
|
|
|
|
Then you can use ArrayList. Here is a sample code:
using System.Collections;
........
ArrayList myList = new ArrayList();
myList.Add(new string(" Here is your string "));
for(int i=0; i<5; i++)
myList.Add(new string(" Here is your string "));
|
|
|
|
|
When i declare array list, this error appear : Erreur 1 The type or namespace name 'ArrayList' could not be found (are you missing a using directive or an assembly reference?) C:\Documents and Settings\Administrateur\Mes documents\Visual Studio 2005\Projects\Form@Home1.0\WindowsApplication2\Form1.cs 20 83 WindowsApplication2
Thank you verry mutch
|
|
|
|
|
You have to insert the next "using" directive at the top of your source file:
using System.Collections;
|
|
|
|
|
Thank you verry mutch, i would use this to read from mylist :
foreach (Array ee in myList) {MessageBox.Show(ee)} , bu there are an exception, thank you verry mutch
|
|
|
|
|
The type of "ee" must be string, not an Array. Use this:
foreach (string ee in myList) {MessageBox.Show(ee)}
|
|
|
|
|
i try for foreach (Object obj in myList), and it work, what is the difference between Object and String ?? thank you verry mutch.
|
|
|
|
|
abbd wrote: there are an exception
That's because there is an error.
If you tell which exception, I can tell you which error.
Well, in this case I can actually tell you anyway. You are reading the items as if they were arrays, but they are strings.
foreach (object ee in myList) { MessageBox.Show((string)ee); }
Unless you are stuck with framework 1, you should use a List<string> instead of ArrayList , so that you don't have to cast every item to string when reading from the list.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Alternatively you can iterate through the elements of an ArrayList like that:
for(int i = 0; i < myList.Count; i++)
MessageBox(myList[i]);
|
|
|
|
|
I have 20000 lignes of string and i would construct a txt file , i make this :
StreamWriter Fichier;
Fichier = File.CreateText(@"C:\CSV1.txt"); <br />
foreach (Object obj in myList)<br />
{ Fichier.WriteLine(obj); } <br />
Fichier.Close();
i know that it take a big space in memory, but i try to optimize the traitement, what is the best for use ? string or object ??, thank you verry mutch.
|
|
|
|
|
If you are a programmer, you should know the difference between String and Object!
And if you don't know the difference, first get lessons or read a book.
Personal I think that you should read a book, because you ask all beginner questions.
First of all, you are probably still using an ArrayList, my suggestion: use List<type>.
Secondly, the difference between a String and Object.
Every String in C# is an Object, but not every Object is a String. Just as that all dogs are animals, but not every animal is a dog. Every type in C# is an Object, so int, String, Array, ArrayList, Double, Byte, those are Objects.
So which should you use, a String or an Object? Well you use a String if you know that the input value is a single or more characters (which will make for instance a sentence or word). If you don't know what the type will be (maybe it is a number, maybe a sentence), you use the Object type.
So you should use a String. Why? You know that the value from a textfile are words or at least characters, so you should store those values in a String.
Good luck!
And you should maybe try work on your English skill, but that's just a side note.
|
|
|
|
|
Dear All,
I have an application which reads an UDP packet sent by a device.
While reading, when the data sent has an value 0 then the byte stream which is read and in the application takes the value as "32" which means space.
I can't replace the byte with value 32 as 0 as in some case the space itself is coming in the stream..
For e.g if the value in byte are 65, 0 then the byte read by the application is 65 and 32.
Kindly help me to resolve the issue.
Thanks a lot in advance.
Best Regards,
M. J. Jaya Chitra
|
|
|
|
|
It sound like you are using something like a stream reader to decode the bytes into text? That would cause any unsupported character codes to change.
How are you doing the actual reading? Do you have any code to show?
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|