Csharp:字符串操作_.NET_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > .NET > Csharp:字符串操作

Csharp:字符串操作

 2013/8/7 16:08:24  ?Geovin Du Dream Park?  博客园  我要评论(0)
  • 摘要:1///<summary>2///字符串操作3///</summary>4publicclassStringControl5{67///<summary>8///客户端浏览器9///http://en.wikipedia.org/wiki/Web_browser10///http://www.w3schools.com/browsers/browsers_stats.asp11///ThemajorwebbrowsersareGoogleChrome
  • 标签:操作 字符串 ARP
  1 /// <summary>
  2     /// 字符串操作
  3     /// </summary>
  4     public class StringControl
  5     {
  6 
  7         /// <summary>
  8         /// 客户端浏览器
  9         /// http://en.wikipedia.org/wiki/Web_browser
 10         /// http://www.w3schools.com/browsers/browsers_stats.asp
 11         /// The major web browsers are Google Chrome, Mozilla Firefox, Internet Explorer, Opera, and Safari.
 12         /// 涂聚文 20130806
 13         /// </summary>
 14         /// <param name="strClient">客户端环境</param>
 15         /// <param name="ver">浏览器版</param>
 16         /// <returns>返回浏览器名称</returns>
 17         public string getBrowser(string strClient, out string ver)
 18         {
 19             string strBrowser = null;
 20             if (strClient.Contains("MSIE") == true)
 21             {
 22                 strBrowser = "Internet Explorer";
 23                 ver = getIEVer(strClient);
 24             }
 25             else if (strClient.Contains("Opera") == true)
 26             {
 27                 strBrowser = "Opera";
 28                 ver = getBrowserVer(strClient, "Version");
 29             }
 30             else if ((strClient.Contains("Firefox") == true) && (strClient.Contains("Chrome") == false) && (strClient.Contains("Safari") == false) && (strClient.Contains("Navigator") == false))
 31             {
 32                 strBrowser = "FireFox";
 33                 ver = getBrowserVer(strClient, "Firefox");
 34 
 35             }
 36             else if ((strClient.Contains("AppleWebKit") == true) && (strClient.Contains("Chrome") == true) && (strClient.Contains("Safari") == true) && (strClient.Contains("Flock") == false))
 37             {
 38                 strBrowser = "Google Chrome";
 39                 ver = getBrowserVer(strClient, "Chrome");
 40             }
 41             else if ((strClient.Contains("Firefox") == true) && (strClient.Contains("Chrome") == false) && (strClient.Contains("Safari") == false) && (strClient.Contains("Navigator") == true))
 42             {
 43                 strBrowser = "Netscape Navigator";
 44                 ver = getBrowserVer(strClient, "Navigator");
 45             }
 46             else if ((strClient.Contains("AppleWebKit") == true) && (strClient.Contains("Flock") == true) && (strClient.Contains("Chrome") == true) && (strClient.Contains("Safari") == true))
 47             {
 48                 strBrowser = "Flock";
 49                 ver = getBrowserVer(strClient, "Flock");
 50             }
 51             else if ((strClient.Contains("AppleWebKit") == true) && (strClient.Contains("Chrome") == false) && (strClient.Contains("Safari") == true))
 52             {
 53                 strBrowser = "Safari";
 54                 ver = getBrowserVer(strClient, "Version");
 55             }
 56             else
 57             {
 58                 strBrowser = "NoData";
 59                 ver = "NoData";
 60             }
 61             return strBrowser;
 62         }
 63         /// <summary>
 64         /// 客户端操作系统
 65         /// http://en.wikipedia.org/wiki/Windows_NT
 66         /// 
 67         /// </summary>
 68         /// <param name="strClient">客户端环境</param>
 69         /// <returns>返回操作系统名称</returns>
 70         public string getPlatform(string strClient)
 71         {
 72             string OpertorSystem = String.Empty;
 73 
 74             if (strClient.Contains("Mac") == true)
 75             {
 76                 return OpertorSystem = "Mac";
 77             }
 78             else if (strClient.Contains("Unix") == true)
 79             {
 80                 return OpertorSystem = "Unix";
 81             }
 82             else if (strClient.Contains("Linux") == true)
 83             {
 84                 return OpertorSystem = "Linux";
 85             }
 86             else if (strClient.Contains("SunOS") == true)
 87             {
 88                 return OpertorSystem = "SunOS";
 89             }
 90             else if (strClient.Contains("Windows NT 3.1") == true)
 91             {
 92                 return OpertorSystem = "Windows NT 3.1";
 93             }
 94 
 95             else if (strClient.Contains("Windows NT 3.5") == true)
 96             {
 97                 return OpertorSystem = "Windows NT 3.5";
 98             }
 99             else if (strClient.Contains("Windows NT 3.51") == true)
100             {
101                 return OpertorSystem = "Windows NT 3.51";
102             }
103             else if (strClient.Contains("Windows NT 4.0") == true)
104             {
105                 return OpertorSystem = "Windows NT 4.0";
106             }
107             else if (strClient.Contains("95") == true)
108             {
109                 return OpertorSystem = "Windows 95";
110             }
111             else if (strClient.Contains("Me") == true)
112             {
113                 return OpertorSystem = "Windows Me";
114             }
115             else if (strClient.Contains("98") == true)
116             {
117                 return OpertorSystem = "Windows 98";
118             }
119             else if (strClient.Contains("Windows NT 5.0") == true)
120             {
121                 return OpertorSystem = "Windows 2000";
122             }
123             else if (strClient.Contains("Windows NT 5.1") == true)
124             {
125                 return OpertorSystem = "Windows XP/Windows Fundamentals";
126             }
127             else if (strClient.Contains("Windows NT  5.2") == true)
128             {
129                 return OpertorSystem = "Windows Server 2003/Windows Home Server";
130             }
131             else if (strClient.Contains("Windows  NT 6.0") == true)
132             {
133                 return OpertorSystem = "Windows Vista/Windows Server 2008";
134             }
135 
136             else if (strClient.Contains("Windows NT 6.1") == true)
137             {
138                 return OpertorSystem = "Windows 7/ Windows Server 2008 R2";
139             }
140             else if (strClient.Contains("Windows NT 6.2") == true)
141             {
142                 return OpertorSystem = "Windows 8/Windows Phone 8/Windows Server 2012";
143             }
144             else if (strClient.Contains("Windows NT 6.3") == true)
145             {
146                 return OpertorSystem = "Windows 8.1";
147             }
148             else
149             {
150                 return OpertorSystem = "NoData";
151             }
152             //OpertorSystem;
153         }
154         /// <summary>
155         /// IE
156         /// </summary>
157         /// <param name="strClient"></param>
158         /// <returns></returns>
159         private string getIEVer(string strClient)
160         {
161             string ver = string.Empty;
162 
163             if (strClient.Contains("MSIE 10.0") == true)
164             {
165                 return ver = "10.0";
166             }
167             if (strClient.Contains("MSIE 9.0") == true)
168             {
169                 return ver = "9.0";
170             }
171             if (strClient.Contains("MSIE 8.0") == true)
172             {
173                 return ver = "8.0";
174             }
175             else if (strClient.Contains("MSIE 7.0") == true)
176             {
177                 return ver = "7.0";
178             }
179             else if (strClient.Contains("MSIE 6.0") == true)
180             {
181                 return ver = "6.0";
182             }
183             else if (strClient.Contains("MSIE 5.0") == true)
184             {
185                 return ver = "5.0";
186             }
187             else
188             {
189                 return ver = "1.0";
190             }
191 
192         }
193         /// <summary>
194         /// 得到版本
195         /// </summary>
196         /// <param name="strClient">客户端环境</param>
197         /// <param name="browere">浏览器名称</param>
198         /// <returns>返回版本号</returns>
199         private string getBrowserVer(string strClient, string browere)
200         {
201             string ver = string.Empty;
202             string[] words = strClient.Split(' ');
203             string browsername = string.Empty;
204             foreach (string word in words)
205             {
206                 if (word.Contains(browere) == true)
207                 {
208                     browsername = word;
209                 }
210                 //Response.Write(word + "<br/>");
211             }
212             //Response.Write("浏览器名称及版本:" + browsername + "<br>");
213             string strnamd = "";
214             //string strver = "";
215             string[] wd = browsername.Split('/');
216             foreach (string nd in wd)
217             {
218                 if (nd.Contains(browere) == true)
219                 {
220                     strnamd = nd;
221                 }
222                 else
223                 {
224                     ver = nd;
225                 }
226             }
227             return ver;
228         }
229         /// <summary>
230         /// 浏览器语言
231         /// http://msdn.microsoft.com/en-us/library/ms533052(VS.85).aspx
232         /// http://www.w3schools.com/tags/ref_language_codes.asp
233         /// http://en.wikipedia.org/wiki/List_of_ISO_639-1_codes
234         /// http://www.metamodpro.com/browser-language-codes
235         /// http://4umi.com/web/html/languagecodes.php
236         /// </summary>
237         /// <param name="strClicent">客户端环境</param>
238         /// <returns>返回浏览语言</returns>
239         public string getBrowserLanguage(string strClicent)
240         {
241             //zh-tw Chinese (Taiwan)  zh-cn Chinese (PRC)  
242             //zh-hk Chinese (Hong Kong SAR)  zh-sg Chinese (Singapore)  
243 
244             string BroswerLanguage = string.Empty;
245             strClicent = strClicent.ToLower();
246             switch (strClicent)
247             {
248                 case "zh-cn":
249                     BroswerLanguage = "zh-cn";//Chinese (PRC) 
250                     break;
251                 case "zh-tw":
252                     BroswerLanguage = "zh-tw";//Chinese (Taiwan) 
253                     break;
254                 case "zh-hk":
255                     BroswerLanguage = "zh-hk";//Chinese (Hong Kong SAR)
256                     break;
257                 case "zh-sg":
258                     BroswerLanguage = "zh-sg";//Chinese (Singapore) 
259                     break;
260                 case "af":
261                     BroswerLanguage = "af";//Afrikaans
262                     break;
263                 case "sq":
264                     BroswerLanguage = "sq";//Albanian
265                     break;
266                 case "ar-sa":
267                     BroswerLanguage = "";//Arabic (Saudi Arabia)
268                     break;
269                 case "ar-iq":
270                     BroswerLanguage = "ar-iq";//Arabic (Iraq)
271                     break;
272                 case "ar-eg":
273                     BroswerLanguage = "ar-eg";//Arabic (Egypt)
274                     break;
275                 case "ar-ly":
276                     BroswerLanguage = "ar-ly";//Arabic (Libya)
277                     break;
278                 case "ar-dz":
279                     BroswerLanguage = "ar-dz";//Arabic (Algeria)
280                     break;
281                 case "ar-ma":
282                     BroswerLanguage = "ar-ma";//Arabic (Morocco)
283                     break;
284                 case "ar-tn":
285                     BroswerLanguage = "ar-tn";//Arabic (Tunisia)
286                     break;
287                 case "ar-om":
288                     BroswerLanguage = "ar-om";//Arabic (Oman)
289                     break;
290                 case "ar-ye":
291                     BroswerLanguage = "ar-ye";//Arabic (Yemen)
292                     break;
293                 case "ar-sy":
294                     BroswerLanguage = "ar-sy";//Arabic (Syria)
295                     break;
296                 case "ar-jo":
297                     BroswerLanguage = "ar-jo";//Arabic (Jordan)
298                     break;
299                 case "ar-lb":
300                     BroswerLanguage = "ar-lb";//Arabic (Lebanon)
301                     break;
302                 case "ar-kw":
303                     BroswerLanguage = "ar-kw";//Arabic (Kuwait)
304                     break;
305                 case "ar-ae":
306                     BroswerLanguage = "ar-ae";//Arabic (U.A.E.)
307                     break;
308                 case "ar-bh":
309                     BroswerLanguage = "ar-bh";//Arabic (Bahrain)
310                     break;
311                 case "ar-qa":
312                     BroswerLanguage = "ar-qa";//Arabic (Qatar)
313                     break;
314                 case "eu":
315                     BroswerLanguage = "Basque";//                    
316                     break;
317                 case "bg":
318                     BroswerLanguage = "bg";//  Bulgarian                  
319                     break;
320                 case "be":
321                     BroswerLanguage = "be";//Belarusian                    
322                     break;
323                 case "ca":
324                     BroswerLanguage = "ca";//Catalan                  
325                     break;
326                 case "hr":
327                     BroswerLanguage = "hr";//Croatian           
328                     break;
329                 case "cs":
330                     BroswerLanguage = "cs";//Czech                 
331                     break;
332                 case "da":
333                     BroswerLanguage = "da";// Danish                 
334                     break;
335                 case "nl":
336                     BroswerLanguage = "nl";//Dutch (Standard)                   
337                     break;
338                 case "nl-be":
339                     BroswerLanguage = "nl-be";// Dutch (Belgium)                 
340                     break;
341                 case "en":
342                     BroswerLanguage = "en";// English 
343                     break;
344                 case "en-us":
345                     BroswerLanguage = "en-us";// English (United States)                 
346                     break;
347                 case "en-gb":
348                     BroswerLanguage = "en-gb";//English (United Kingdom)                   
349                     break;
350                 case "en-au":
351                     BroswerLanguage = "en-au";// English (Australia)                    
352                     break;
353                 case "en-ca":
354                     BroswerLanguage = "en-ca";//  English (Canada)                   
355                     break;
356                 case "en-nz":
357                     BroswerLanguage = "en-nz";//  English (New Zealand)                   
358                     break;
359                 case "en-ie":
360                     BroswerLanguage = "en-ie";//   English (Ireland)                  
361                     break;
362                 case "en-za":
363                     BroswerLanguage = "en-za";//    English (South Africa)                 
364                     break;
365                 case "en-jm":
366                     BroswerLanguage = "en-jm";//   English (Jamaica)                  
367                     break;
368                 //case "en":
369                 //    BroswerLanguage = "en";//  English (Caribbean)                   
370                 //    break;
371                 case "en-bz":
372                     BroswerLanguage = "en-bz";//   English (Belize)                 
373                     break;
374                 case "en-tt":
375                     BroswerLanguage = "en-tt";//    English (Trinidad)                
376                     break;
377                 case "et":
378                     BroswerLanguage = "et";//   Estonian                   
379                     break;
380                 case "fo":
381                     BroswerLanguage = "fo";//  Faeroese                   
382                     break;
383                 case "fa":
384                     BroswerLanguage = "fa";//  Farsi                   
385                     break;
386                 case "fi":
387                     BroswerLanguage = "fi";//    Finnish                 
388                     break;
389                 case "fr":
390                     BroswerLanguage = "fr";//  French (Standard)                   
391                     break;
392                 case "fr-be":
393                     BroswerLanguage = "fr-be";//   French (Belgium)               
394                     break;
395                 case "fr-ca":
396                     BroswerLanguage = "fr-ca";//   French (Canada)                  
397                     break;
398                 case "fr-ch":
399                     BroswerLanguage = "fr-ch";//   French (Switzerland)                  
400                     break;
401                 case "fr-lu":
402                     BroswerLanguage = "fr-lu";//   French (Luxembourg)                  
403                     break;
404                 case "gd":
405                     BroswerLanguage = "";//   Gaelic (Scotland)                  
406                     break;
407                 case "gd-ie":
408                     BroswerLanguage = "";// Gaelic (Ireland)                    
409                     break;
410                 case "de":
411                     BroswerLanguage = "";//  German (Standard)                   
412                     break;
413                 case "de-ch":
414                     BroswerLanguage = "";//   German (Switzerland)                  
415                     break;
416                 case "de-at":
417                     BroswerLanguage = "";//    German (Austria)                 
418                     break;
419                 case "de-lu":
420                     BroswerLanguage = "";// German (Luxembourg)                    
421                     break;
422                 case "de-li":
423                     BroswerLanguage = "";//   German (Liechtenstein)                 
424                     break;
425                 case "el":
426                     BroswerLanguage = "el";//   Greek                 
427                     break;
428                 case "he":
429                     BroswerLanguage = "he";//  Hebrew                   
430                     break;
431                 case "hi":
432                     BroswerLanguage = "hi";// Hindi                    
433                     break;
434                 case "hu":
435                     BroswerLanguage = "hu";// Hungarian                    
436                     break;
437                 case "is":
438                     BroswerLanguage = "is";//    Icelandic                 
439                     break;
440                 case "id":
441                     BroswerLanguage = "id";//   Indonesian                  
442                     break;
443                 case "it":
444                     BroswerLanguage = "it";// Italian (Standard)                    
445                     break;
446                 case "it-ch":
447                     BroswerLanguage = "it-ch";//  Italian (Switzerland)                  
448                     break;
449                 case "ja":
450                     BroswerLanguage = "ja";// Japanese                    
451                     break;
452                 case "ko":
453                     BroswerLanguage = "ko";//   Korean /Korean (Johab)                  
454                     break;
455                 //case "ko":
456                 //    BroswerLanguage = "ko";// Korean (Johab)                    
457                 //    break;
458                 case "lv":
459                     BroswerLanguage = "lv";//  Latvian                  
460                     break;
461                 case "lt":
462                     BroswerLanguage = "lt";//Lithuanian                     
463                     break;
464                 case "mk":
465                     BroswerLanguage = "mk";//    FYRO Macedonian ms Malaysian                
466                     break;
467                 case "mt":
468                     BroswerLanguage = "mt";//  Maltese                  
469                     break;
470                 case "no":
471                     BroswerLanguage = "no";//    Norwegian (Bokmal)                 
472                     break;
473                 //case "no":
474                 //    BroswerLanguage = "no";//   Norwegian (Nynorsk)                  
475                 //    break;
476                 case "pl":
477                     BroswerLanguage = "pl";// Polish                    
478                     break;
479                 case "pt-br":
480                     BroswerLanguage = "pt-br";//  Portuguese (Brazil)                   
481                     break;
482                 case "pt":
483                     BroswerLanguage = "pt";// Portuguese (Portugal)                    
484                     break;
485                 case "rm":
486                     BroswerLanguage = "rm";// Rhaeto-Romanic              
487                     break;
488                 case "ro":
489                     BroswerLanguage = "ro";// Romanian                    
490                     break;
491                 case "ro-mo":
492                     BroswerLanguage = "ro-mo";//   Romanian (Moldavia)                  
493                     break;
494                 case "ru":
495                     BroswerLanguage = "ru";// Russian                    
496                     break;
497                 case "ru-mo":
498                     BroswerLanguage = "ru-mo";//   Russian (Moldavia)                  
499                     break;
500                 case "sz":
501                     BroswerLanguage = "sz";//   Sami (Lappish)                  
502                     break;
503                 case "sr":
504                     BroswerLanguage = "sr";//  Serbian (Cyrillic)                   
505                     break;
506                 //case "sr":
507                 //    BroswerLanguage = "sr";// Serbian (Latin)                   
508                 //    break;
509                 case "sk":
510                     BroswerLanguage = "sk";//  Slovak                   
511                     break;
512                 case "sl":
513                     BroswerLanguage = "sl";// Slovenian             
514                     break;
515                 case "sb":
516                     BroswerLanguage = "sb";//    Sorbian                 
517                     break;
518                 case "es":
519                     BroswerLanguage = "es";//  Spanish (Spain, traditional)                  
520                     break;
521                 //case "es":
522                 //    BroswerLanguage = "es";//    Spanish (Spain, modern)                    
523                 //    break;
524                 case "es-ar":
525                     BroswerLanguage = "es-ar";//  Spanish (Argentina)                  
526                     break;
527                 case "es-gt":
528                     BroswerLanguage = "es-gt";//  Spanish (Guatemala)                   
529                     break;
530                 case "es-cr":
531                     BroswerLanguage = "es-cr";//Spanish (Costa Rica)                     
532                     break;
533                 case "es-pa":
534                     BroswerLanguage = "es-pa";// Spanish (Panama)                    
535                     break;
536                 case "es-do":
537                     BroswerLanguage = "es-do";// Spanish (Dominican Republic)               
538                     break;
539                 case "es-mx":
540                     BroswerLanguage = "es-mx";// Spanish (Mexico)                    
541                     break;
542                 case "es-ve":
543                     BroswerLanguage = "es-ve";//Spanish (Venezuela)      
544                     break;
545                 case "es-co":
546                     BroswerLanguage = "es-co";//   Spanish (Colombia)                  
547                     break;
548                 case "es-pe":
549                     BroswerLanguage = "es-pe";// Spanish (Peru)                    
550                     break;
551                 case "es-ec":
552                     BroswerLanguage = "es-ec";//  Spanish (Ecuador)                  
553                     break;
554                 case "es-cl":
555                     BroswerLanguage = "es-cl";// Spanish (Chile)                    
556                     break;
557                 case "es-uy":
558                     BroswerLanguage = "es-uy";//  Spanish (Uruguay)                   
559                     break;
560                 case "es-py":
561                     BroswerLanguage = "es-py";//  Spanish (Paraguay)                  
562                     break;
563                 case "es-bo":
564                     BroswerLanguage = "es-bo";// Spanish (Bolivia)                   
565                     break;
566                 case "es-sv":
567                     BroswerLanguage = "es-sv";// Spanish (El Salvador)                    
568                     break;
569                 case "es-hn":
570                     BroswerLanguage = "es-hn";// Spanish (Honduras)                    
571                     break;
572                 case "es-ni":
573                     BroswerLanguage = "es-ni";// Spanish (Nicaragua)                   
574                     break;
575                 case "es-pr":
576                     BroswerLanguage = "es-pr";//   Spanish (Puerto Rico)                 
577                     break;
578                 case "sx":
579                     BroswerLanguage = "sx";//     Sutu                
580                     break;
581                 case "sv":
582                     BroswerLanguage = "sv";//  Swedish                   
583                     break;
584                 case "sv-fi":
585                     BroswerLanguage = "sv-fi";// Swedish (Finland)                    
586                     break;
587                 case "th":
588                     BroswerLanguage = "th";// Thai                    
589                     break;
590                  case "ts":
591                     BroswerLanguage = "";//  Tsonga                   
592                     break;
593                 case "tn":
594                     BroswerLanguage = "tn";//  Tswana                   
595                     break;
596                  case "tr":
597                     BroswerLanguage = "tr";//  Turkish                   
598                     break;
599                 case "uk":
600                     BroswerLanguage = "uk";//  Ukrainian                   
601                     break;
602                  case "ur":
603                     BroswerLanguage = "ur";// Urdu                    
604                     break;
605                 case "ve":
606                     BroswerLanguage = "ve";// Venda                    
607                     break;
608                 case "vi":
609                     BroswerLanguage = "vi";//  Vietnamese                  
610                     break;
611                 case "xh":
612                     BroswerLanguage = "xh";//   Xhosa                  
613                     break;
614                 case "ji":
615                     BroswerLanguage = "ji";//  Yiddish                   
616                     break;
617                 case "zu":
618                     BroswerLanguage = "zu";//Zulu                    
619                     break;
620                 // case "":
621                 //    BroswerLanguage = "";//                    
622                 //    break;
623                 //case "":
624                 //    BroswerLanguage = "";//                    
625                 //    break;
626                 default:
627                     BroswerLanguage = "NoData";
628                     break;
629             }
630             return BroswerLanguage;
631 
632             //if (strClicent.Contains("zh-cn") == true)
633             //{
634             //    return BroswerLanguage = "zh-cn";
635             //}
636             //if (strClicent.Contains("zh-tw") == true)
637             //{
638             //    return BroswerLanguage = "zh-tw";
639             //}
640             //if (strClicent.Contains("zh-hk") == true)
641             //{
642             //    return BroswerLanguage = "zh-hk";
643             //}
644             //if (strClicent.Contains("zh-sg") == true)
645             //{
646             //    return BroswerLanguage = "zh-sg";
647             //}
648             //else if (strClicent.Contains("en-us") == true)
649             //{
650             //    return BroswerLanguage = "en-us";
651             //}
652             //else
653             //{
654             //    return BroswerLanguage = "NoData";
655             //}
656 
657         }
658     }

 

发表评论
用户名: 匿名