{"id":2085,"date":"2015-03-06T14:55:50","date_gmt":"2015-03-06T06:55:50","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=2085"},"modified":"2015-03-06T17:48:49","modified_gmt":"2015-03-06T09:48:49","slug":"%e6%8c%89%e8%87%aa%e7%84%b6%e8%af%ad%e8%a8%80%e8%a7%84%e5%88%99%e8%bf%9b%e8%a1%8c%e5%ad%97%e7%ac%a6%e4%b8%b2%e6%8e%92%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=2085","title":{"rendered":"\u6309\u81ea\u7136\u8bed\u8a00\u89c4\u5219\u8fdb\u884c\u5b57\u7b26\u4e32\u6392\u5e8f"},"content":{"rendered":"<p>QString \u65b0\u63d0\u4f9b\u4e86\u4e00\u4e2a NaturalCompareW \u51fd\u6570\uff08\u517c\u5bb9Delphi\/C++ Builder 2007+\uff09\u4e3a\u5927\u5bb6\u63d0\u4f9b\u6309\u81ea\u7136\u8bed\u8a00\u89c4\u5219\u8fdb\u884c\u6bd4\u8f83\u5927\u5c0f\uff0c\u4e5f\u5c31\u662f\u6240\u8c13\u7684\u81ea\u7136\u6392\u5e8f\u3002\u6240\u8c13\u7684\u81ea\u7136\u6392\u5e8f\u662f\u6307\u50cf\u5b57\u6bcd\u540e\u9762\u8ddf\u6570\u5b57\u7684\u60c5\u51b5\u4e0b\uff0c\u4e0d\u662f\u6309\u7167\u5b57\u7b26\u672c\u8eab\u7684\u987a\u5e8f\uff0c\u800c\u662f\u6309\u7167\u6570\u5b57\u7684\u503c\u7684\u987a\u5e8f\u8fdb\u884c\u6392\u5e8f\u3002\u5982\uff1aA2 A10 A1 \u8fd9\u4e09\u4e2a\u5b57\u7b26\u4e32\uff0c\u6309\u4e00\u822c\u7684\u8ba1\u7b97\u673a\u5185\u90e8\u6392\u5e8f\u7b97\u6cd5\u662f A1 A10 A2\uff0c\u800c\u6309\u81ea\u7136\u6392\u5e8f\u7684\u8bdd\uff0c\u987a\u5e8f\u5e94\u4e3a\uff1aA1 A2 A10\u3002<\/p>\n<p>\u6211\u4eec\u5148\u770b\u4e00\u4e0b\u8fd9\u4e2a\u51fd\u6570\u7684\u58f0\u660e\uff1a<\/p>\n<pre class=\"lang:delphi decode:true \">\/\/\/ &lt;summary&gt;\u4f7f\u7528\u81ea\u7136\u8bed\u8a00\u89c4\u5219\u6bd4\u8f83\u5b57\u7b26\u4e32&lt;\/summary&gt;\r\n\/\/\/ &lt;param name=\"s1\"&gt;\u7b2c\u4e00\u4e2a\u8981\u6bd4\u8f83\u7684\u5b57\u7b26\u4e32&lt;\/param&gt;\r\n\/\/\/ &lt;param name=\"s2\"&gt;\u7b2c\u4e8c\u4e2a\u8981\u6bd4\u8f83\u7684\u5b57\u7b26\u4e32&lt;\/param\r\n\/\/\/ &lt;param name=\"AIgnoreCase\"&gt;\u6bd4\u8f83\u65f6\u662f\u5426\u5ffd\u7565\u5927\u5c0f\u5199&lt;\/param&gt;\r\n\/\/\/ &lt;remarks&gt;\u672c\u6bd4\u8f83\u8003\u8651\u4e2d\u6587\u5168\u89d2\u7684\u60c5\u51b5\uff0c\u8ba4\u4e3a\u4e2d\u6587\u5168\u89d2\u7b26\u53f7\u548c\u5bf9\u5e94\u7684\u534a\u89d2\u7b26\u53f7\u662f\u76f8\u7b49\u7684\u503c&lt;\/remarks&gt;\r\nfunction NaturalCompareW(s1, s2: PQCharW; AIgnoreCase: Boolean): Integer;<\/pre>\n<p>\u53c2\u6570\u8bf4\u660e\u5728\u4e0a\u9762\u7684\u58f0\u660e\u4e2d\u5df2\u7ecf\u63cf\u8ff0\u7684\u6bd4\u8f83\u6e05\u695a\u4e86\uff0c\u6211\u4eec\u5728\u5176\u4e2d\u5904\u7406\u4e86\u5168\u89d2\u5b57\u7b26\u7684\u60c5\u51b5\uff0c\u5728\u4e2d\u6587\u81ea\u7136\u6392\u5e8f\u89c4\u5219\u4e2d\uff0c\u6211\u4eec\u8ba4\u4e3a\u5168\u89d2\u548c\u534a\u89d2\u5bf9\u5e94\u7684\u540c\u4e00\u4e2a\u5b57\u7b26\u3002<\/p>\n<p>\u4e0b\u9762\u662f\u4e00\u6bb5\u793a\u4f8b\u4ee3\u7801\uff0c\u5bf9 Memo1 \u4e2d\u7528\u6237\u8f93\u5165\u00a0\u7684\u5185\u5bb9\u8fdb\u884c\u81ea\u7136\u8bed\u8a00\u6392\u5e8f\uff0c\u7136\u540e\u8f93\u51fa\u5230 Memo2 \u4e2d\u3002<\/p>\n<pre class=\"lang:delphi decode:true \">unit Unit1;\r\n\r\ninterface\r\n\r\nuses\r\n  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,\r\n  System.Classes, Vcl.Graphics,\r\n  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;\r\n\r\ntype\r\n  TForm1 = class(TForm)\r\n    Button1: TButton;\r\n    Memo1: TMemo;\r\n    Memo2: TMemo;\r\n    CheckBox1: TCheckBox;\r\n    procedure Button1Click(Sender: TObject);\r\n  private\r\n    { Private declarations }\r\n  public\r\n    { Public declarations }\r\n  end;\r\n\r\nvar\r\n  Form1: TForm1;\r\n\r\nimplementation\r\n\r\nuses QString;\r\n{$R *.dfm}\r\n\r\nfunction NCmp(List: TStringList; Index1, Index2: Integer): Integer;\r\nbegin\r\nResult := NaturalCompareW(PQCharW(List[Index1]), PQCharW(List[Index2]), false);\r\nend;\r\n\r\nfunction NCmpI(List: TStringList; Index1, Index2: Integer): Integer;\r\nbegin\r\nResult := NaturalCompareW(PQCharW(List[Index1]), PQCharW(List[Index2]), true);\r\nend;\r\n\r\nprocedure TForm1.Button1Click(Sender: TObject);\r\nvar\r\n  AList: TStringList;\r\nbegin\r\nAList := TStringList.Create;\r\nAList.AddStrings(Memo1.Lines);\r\nif CheckBox1.Checked then\r\n  AList.CustomSort(NCmpI)\r\nelse\r\n  AList.CustomSort(NCmp);\r\nMemo2.Lines.Assign(AList);\r\nFreeObject(AList);\r\nend;\r\n\r\nend.<\/pre>\n<p>\u5b9e\u9645\u8fd0\u884c\u6548\u679c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n<p>1\u3001\u533a\u5206\u5927\u5c0f\u5199\uff1a<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-2092\" src=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2015\/03\/NaturalCompare1.jpg\" alt=\"NaturalCompare1\" width=\"580\" height=\"455\" srcset=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2015\/03\/NaturalCompare1.jpg 580w, https:\/\/blog.qdac.cc\/wp-content\/uploads\/2015\/03\/NaturalCompare1-300x235.jpg 300w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/p>\n<p>2\u3001\u5ffd\u7565\u5927\u5c0f\u5199<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-large wp-image-2093\" src=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2015\/03\/NaturalCompare2.jpg\" alt=\"NaturalCompare2\" width=\"580\" height=\"455\" srcset=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2015\/03\/NaturalCompare2.jpg 580w, https:\/\/blog.qdac.cc\/wp-content\/uploads\/2015\/03\/NaturalCompare2-300x235.jpg 300w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/p>\n<p>\u672c\u6f14\u793a\u7a0b\u5e8f\u4e0b\u8f7d\uff1a<\/p>\n<p><a href=\"http:\/\/pan.baidu.com\/s\/1c0gw3YS\" target=\"_blank\">\u767e\u5ea6\u7f51\u76d8<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>QString \u65b0\u63d0\u4f9b\u4e86\u4e00\u4e2a Natur [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[69,8,9,21],"tags":[348],"class_list":["post-2085","post","type-post","status-publish","format-standard","hentry","category-c-builder","category-delphi","category-qdac","category-misc","tag-348"],"views":9798,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/2085","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2085"}],"version-history":[{"count":4,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/2085\/revisions"}],"predecessor-version":[{"id":2096,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/2085\/revisions\/2096"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2085"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2085"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2085"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}