c#orderby错误的订购 [英] c# orderby wrong ordering

查看:72
本文介绍了c#orderby错误的订购的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using (var client = new WebClient())
                {
                    var html = client.DownloadString(video.Url);

                    // HtmlAgilityPack class
                    var htmlDoc = new HtmlAgilityPack.HtmlDocument();

                    htmlDoc.LoadHtml(html);

                    var htmlElement = htmlDoc.DocumentNode.Element("meta");

                    HtmlNode mdnode = htmlDoc.DocumentNode.SelectSingleNode("//meta[@name='keywords']");

                   
                        var htmlAtribute = mdnode.Attributes["content"];

                        string fulldescription = htmlAtribute.Value;
                        byte[] bytes = Encoding.Default.GetBytes(fulldescription);
                        fulldescription = Encoding.UTF8.GetString(bytes);
                        string text = fulldescription;


                    Collection<string> collection = new Collection<string>();
                    string[] bits = text.Split(',');

                    foreach (string rr in bits)
                    {
                        collection.Add(rr);

                    }

                     
                        var sortedElements = from rr in collection
                                             orderby rr.Length descending
                                             select rr;
                    foreach (string c in sortedElements)
                    {


                        listbox1.Items.Add(c);



                    }
                }

            }

输出:(如您所见,它是按部分排序,但我想要完整的订单,其中应包括列表框中的所有项目 

The Output :( As you can see , it is ordering part by part, but i want full order which should includes all items in the listbox 

推荐答案

这里有使用浏览器的F12工具并检查列表框中的实际内容。在每个字符串的开头可能有多余的空格或不可显示的字符。

There's some random indenting there. Use the browser's F12 tools and check to see what is actually in the listbox. You may have excess spaces or non-displayable characters at the beginning of each string.

At最小化,在将字符串添加到集合之前修剪字符串。

At a minimum, trim the strings before adding them to the collection.


这篇关于c#orderby错误的订购的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆