Resolved Console.write/writeline not working as my expected

Joined
Dec 21, 2020
Messages
14
Programming Experience
Beginner
Here is the thing. What I want is to print out the time, price , change, Premium , and the Nprice(price in real) at the same row. Like :
10:13:16 Price:10300 change: +100 Premium : +5 Nprice: 10295

but if I try to put all in a row, some of data would disappear:
Console.Write() missing out some string /variance:
                WebClient httpins = new WebClient();
                httpins.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:84.0) Gecko/20100101 Firefox/84.0");
                httpins.Headers.Add("Method", "GET");


                DateTime now = DateTime.Now;
                Stream resp = httpins.OpenRead(http);
                StreamReader resstring = new StreamReader(resp);
                string s = resstring.ReadToEnd();
                HtmlDocument doc = new HtmlDocument();
                doc.LoadHtml(s);              
                resstring.Close();
                HtmlNode pricenode = doc.DocumentNode.SelectSingleNode("html/body/form/div[4]/div/div[4]/div[5]/table/tr/td/div[4]");
                HtmlNode pricenow = doc.DocumentNode.SelectSingleNode("html/body/form/div[4]/div/div[4]/div[5]/table/tr[7]/td/div[5]");
                HtmlNode change = doc.DocumentNode.SelectSingleNode("html/body/form/div[4]/div/div[4]/div[5]/table/tr[7]/td/div[7]");
                HtmlNode premium = doc.DocumentNode.SelectSingleNode("html/body/form/div[4]/div/div[4]/div[5]/table/tr/td[3]/div[4]/span");
                Console.WriteLine(now.ToString("T"));
                Console.WriteLine($"Price: {pricenode.InnerText}");
                Console.WriteLine($"NChange: {change.InnerText}");
                Console.WriteLine($"Premium: {premium.InnerText}");
                Console.WriteLine($"NPrice: {pricenow.InnerText}");
                Console.WriteLine("---------------------------------------------------");//down there is what i want
                Console.Write(now.ToString("T") + $"Price: {pricenode.InnerText} Nchange: {change.InnerText} Premium: {premium.InnerText} Nprice: {pricenow.InnerText}");


The output would like:
下午 06:26:54
10,439 <-------------even I separate the data, I lost the string this time
NChange: -51.99 (0.50%)
Premium: 高水&nbsp;8
NPrice: 10,430.53
---------------------------------------------------
Nchange: -51.99 (0.50%) Premium: 高水&nbsp;8 Nprice: 10,430.53 <-------Time and Price is missing



I want to repeatedly execute the program and update the data periodically.So would be better if I can able to see all on a single row.

Seeking Help
 
I get this output:
12.02.24
Price:
10,439

NChange: -51.99 (0.50%)
Premium: 高水&nbsp;8
NPrice: 10,430.53
---------------------------------------------------
12.02.24Price:
10,439
Nchange: -51.99 (0.50%) Premium: 高水&nbsp;8 Nprice: 10,430.53
All data is there, but some values have linefeeds and whitespace, look at the pricenode:
1609067155510.png

Here you can trim the string to remove that. String.Trim Method (System)
 
I get this output:

All data is there, but some values have linefeeds and whitespace, look at the pricenode: View attachment 1287
Here you can trim the string to remove that. String.Trim Method (System)
I think I know exactly what you mean, But I don't know how exactly should I do to obstain the same output as you do.
Could you mind to share those modify code to me?
 
If you knew exactly what he meant, then you understood that there were characters that you needed to trim away.
 
?Thank you. I understand now.
C#:
Console.WriteLine(now.ToString("T") + $" Price: {pricenode.InnerText.Trim()} Nchange: {change.InnerText.Trim()} Premium: {premium.InnerText.Replace("&nbsp;", " ").Trim()} Nprice: {pricenow.InnerText.Trim()}");
 
Back
Top Bottom