Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

C#, label ignores parts of the given text

i need to put in my label something like "x rub | y%" but label ignores the rest of text after the x.
when the label gets "0" value, it works as i want it to, i.e. "0$. | 0%", but whenever the value isnt 0, it only displays "read_cat"’s value ("2000"). Thank you in advance.

System.IO.StreamReader reading2 = File.OpenText("categories\\clothes.txt");
read_cat1 = Convert.ToString(File.ReadAllText("categories\\clothes.txt")); 
clothes_percentage.Text = Convert.ToString(read_cat1) +"$ | "+ 
Convert.ToString(Math.Round(Convert.ToDouble(read_cat1) * 100 / salary, 2))+"%";
reading2.Close();

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

My guess is that your file contains a linebreak after the actual value. Use the Trim() method to remove linebreaks and other whitespace from the string you read from the file.

string read_cat1 = File.ReadAllText("categories\\clothes.txt"); 
read_cat1 = read_cat1.Trim();
clothes_percentage.Text = read_cat1 + "$ | " + 
    Math.Round(Convert.ToDouble(read_cat1) * 100 / salary, 2) +"%";
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading