473,406 Members | 2,816 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,406 software developers and data experts.

Simple StreamReader issue

134 100+
I am trying to use a text file to save the language my program needs to use. And saving the language in the text file goes fine. Also retrieving the language from it goes fine. But using the retrieved string to catch a language from it won't succeed. And somehow it won't work no matter what I try.

This is my code:

Expand|Select|Wrap|Line Numbers
  1. public static string language = "";
  2.  
  3.         private void ExtensionSearcher_Load(object sender, EventArgs e)
  4.         {
  5.             try
  6.             {
  7.                 if (File.Exists("setup.txt"))
  8.                 {
  9.                     StreamReader sr = new StreamReader("setup.txt");
  10.  
  11.                     language = sr.ReadToEnd();
  12.  
  13.                     MessageBox.Show(language);
  14.  
  15.                     switch (language)
  16.                     {
  17.                         case "Nederlands":
  18.                             lblSearchExt.Text = "Zoek op extensie";
  19.                             lblSearchType.Text = "Zoek op type";
  20.                             lblSearchProgram.Text = "Zoek op programma";
  21.                             lblExtList.Text = "Extensies";
  22.                             lblTypeList.Text = "Types";
  23.                             lblProgramList.Text = "Programma's";
  24.                             break;
  25.                         case "English":
  26.                             lblSearchExt.Text = "Search by extension";
  27.                             lblSearchType.Text = "Search by type";
  28.                             lblSearchProgram.Text = "Search by program";
  29.                             lblExtList.Text = "Extensions";
  30.                             lblTypeList.Text = "Types";
  31.                             lblProgramList.Text = "Programs";
  32.                             break;
  33.                     }
  34.                 }
  35.  
Mar 2 '12 #1
6 1622
GaryTexmo
1,501 Expert 1GB
Are you saying none of your cases are hit?

Can you please post the contents (or at least, the relevant contents) of setup.txt?
Mar 2 '12 #2
michaeldebruin
134 100+
ow I see now, sorry that I didn't explain the issue. But yes idd none of the cases are hit. When using simple installer, to write the language in a text file and in this case English or Nederlands. None of the cases are hit after the using the streamreader.

The only thing which is writtin in the file is English or Nederlands.
Mar 2 '12 #3
GaryTexmo
1,501 Expert 1GB
Oh! Inspect the contents of language directly. Output the length if you have to, or even inspect the ASCII codes. I'd be willing to bet that when you do a ReadToEnd there you're picking up a trailing newline, or perhaps some other end of file type character.

Take a look :)
Mar 3 '12 #4
michaeldebruin
134 100+
Do you think a ReadLine would do the trick? Or use a special character like / to split the string which I want to retrieve from the other stuff?
Mar 3 '12 #5
GaryTexmo
1,501 Expert 1GB
You could try any number of things. A readline would likely work, or a string.Trim. You could also store it in XML.

Any number of things really :) Just verify the contents of your string using the debugger if your compares aren't working. That's usually a good starting point.
Mar 3 '12 #6
michaeldebruin
134 100+
Oke well thanks for all the help. I think it can be done way easier. But now I've added a special character to it (in the case that I am going to write some more in the text file). And then used a string.trim to get the language from it. And then just added a if statement to say that when the language is English it is English and for some reason the case of English got hit. And the same is for the case Nederlands (or Dutch). I don't know what the real issue was, but it finally works :).
Mar 3 '12 #7

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

Similar topics

0
by: Bud Curtis | last post by:
For some reason on my system I can't get the following elementry web.xml to validate. It looks like JonAS will only process an XML if it is valid. For some reason a very similar web.xml on JBoss...
5
by: Christopher Benson-Manica | last post by:
I'm trying to dynamically change the contents of a select box by doing the following... function myfunc() { var obj=document.getElementById("objname"); // name of the select box var str='';...
7
by: | last post by:
Hello, I do not understand why the func getName() does not receive any data (actually, none of the get__receive any data. The class I am using as an almost exact example (the exception being...
4
by: Shane | last post by:
Thanks in advance for your help. I have created several classes that each have their own member functions that allow them to print the data stored int their respective classes. In other words,...
4
by: Brian Mink | last post by:
I am having trouble getting one database to export data that another one can import. The problem is a dash "-". I have a group of numbers entered in my database that have a dash in them (e.g....
5
by: Newbie | last post by:
Hi all, Just want to comment on this thread. Seems like every discussion about this matter (setting up DB provider for membership) and all the samples/references given by some MVPs always...
1
by: Newbie | last post by:
Hi all, Just want to comment on this thread. Seems like every discussion about this matter (setting up DB provider for membership) and all the samples/references given by some MVPs always...
6
by: Christof Warlich | last post by:
Hi, can anyone tell how to convince the compiler to accept the third line in the example below? I need this parameter sequence because I want to define a default argument for T , e.g.:...
5
by: 0xception | last post by:
Hi, I'm attempting to create a perl script that will modify a series of RRD databases (a couple hundred of them). in order to do this the RRD database can be exported to XML modified and then...
1
by: GinnTech | last post by:
Hello, I have an issue with the CreateUserWizard Control. I am trying to once the user is successfully created add them to a default role. So crazy me to think that I would leverage the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.