{"id":1661,"date":"2012-08-17T09:17:17","date_gmt":"2012-08-17T09:17:17","guid":{"rendered":"http:\/\/www.ericwhite.com\/home2\/bm8qcmjy\/public_html\/blog\/?p=1661"},"modified":"2012-08-17T09:17:17","modified_gmt":"2012-08-17T09:17:17","slug":"sorting-text-in-visual-studio","status":"publish","type":"post","link":"https:\/\/www.ericwhite.com\/blog\/2012\/08\/17\/sorting-text-in-visual-studio\/","title":{"rendered":"Sorting Text in Visual Studio"},"content":{"rendered":"<p>Sometimes you need to sort some lines of code in Visual Studio &#8211; for instance, if you have a long list of Open XML content types, Open XML relationship types, or elements names, you may want that list to be sorted. Here is a little VB snippet (<a href=\"http:\/\/stackoverflow.com\/questions\/3350793\/sort-selected-text-from-visual-studio-context-menu\">from stackoverflow<\/a>) that sorts text.<\/p>\n<pre>Sub SortLines()\r\n    Dim Selection As TextSelection = DTE.ActiveDocument.Selection\r\n    Dim Lines() As String = Selection.Text.Replace(Environment.NewLine, Chr(13)).Split(Chr(13))\r\n    Array.Sort(Lines)\r\n    DTE.UndoContext.Open(\"Sort Lines\")\r\n    ' Edit - see comments\r\n    ' Selection.Text = String.Join(Environment.NewLine, Lines)\r\n    Selection.Delete()\r\n    Selection.Insert(String.Join(Environment.NewLine, Lines))\r\n    DTE.UndoContext.Close()\r\nEnd Sub<\/pre>\n<p>Posting this here so I can find it again easily.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sometimes you need to sort some lines of code in Visual Studio &#8211; for instance, if you have a long list of Open XML content types, Open XML relationship types, or elements names, you may want that list to be sorted. Here is a little VB snippet (from stackoverflow) that sorts text. Sub SortLines() Dim [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"_s2mail":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-1661","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/posts\/1661","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/comments?post=1661"}],"version-history":[{"count":1,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/posts\/1661\/revisions"}],"predecessor-version":[{"id":1662,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/posts\/1661\/revisions\/1662"}],"wp:attachment":[{"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/media?parent=1661"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/categories?post=1661"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ericwhite.com\/blog\/wp-json\/wp\/v2\/tags?post=1661"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}