0

您好,我是初学者,我需要制作一个工具来从文本文件中转储一些我需要的代码。

这是文本文件的外观

79nxO´.[„Ò€D JƒÚY S 4 A4B67368-30F84CD6-930CEA07-C2645CDC lÁ°uµ¥?_2¶›]éÚ[™tiipDAe LƒÚX S 4
1E2F44FA-19F77EC4-8212CEBF-6A196C36 é9£ð÷å“™—3 -šÍïiÃä{r&GŠ JƒÚW S 4 65735EC4-415C4232-91691832-8A8BE21F!VoS Z˜©giàë½ÓX³ÁUhÛÇÖò LƒÚV S 4
CD3B3376-4638422A-A171BB50-00D194CC Û¾A@X "|ÂÒ9þ-¶=M¬°E¾+ JƒÚU S 4
00D1996F-7F834C0F -A7B7F798-7CA393DE!¥£à«auA¾¼¢~•ÈÖk}®~¤ JƒÚT S 4 8656E931-79CC8FFE-B11B168F-FEB84D92 ?Ø #` IÐ]dÒ"ÎÑfþ0Äõ-®"€<³= JƒÚN S 4 E4D327F0 DE664C4E-BA1644BF-F0E5221C ¿Ptô(F3Ù™°Ú¹•žÒQÁü* JƒÚM S 4 9671B975-D90D4854-9F3FAE97-A8F24DD2 ª°®õËÛH?y[ÛvN;ÿC‹[ JƒÚL S 4 82A717AB-8A0546EE-916657E9-FA87BD44 ={ÃPHÕÔŽš „ôгÒmâ ße5½j&u JƒÚK S 4 9BD782BF-8E684DDC-B987FD8F-EF10871F :—w°ALR-•ÿ•àz/N.ý–v~arÚ LƒÚJ S 47pñBŽj¦Ù\ üXáæƒÕfø JƒÚS S 4 B72C3724-880944E8-B3B4CC58-EB7EB7E7 - 0íi/è+›N -‘”rU’[p$ JƒÚR S 4
CD9A4A87-1119464B-934C46AE-A36CF157 *µË0´eb€Ò;D Y6µ»Õ£”ê JƒÚQ S 4 BC7F993F-A87F450F-A1BCC1E6-1FC9518D (>þЬ0®žðR®ZV[óL¨¨lŒ;ôm¤ LƒÚP S 4
A3F8CC05-BABB4DB6-97E47D7E-7428D2CA ÜÌ ðs4¸ÌÏF¦Xf=êmHšÍÄô JƒÚO S 4 C0A2FEE7-C0264D80-A1F8705A-EEA24595



AC87845A-B7B64B22-A293D713-C46739F0 Ô¥60'8Ä|I'Ýc¿!\¨ÃlçÒ JƒÚI

例如,这是一个代码“A4B67368-30F84CD6-930CEA07-C2645CDC”,我需要从文件中获取它们。

4

2 回答 2

3

您可以使用正则表达式轻松解析目标代码:

' copy & paste your string here, be sure to escape quotes properly
Dim s As String = "INSERT YOUR STRING HERE"

Dim rx As Regex
Dim m As MatchCollection

' This Regular Expression looks for a pattern like xxxxxxxx-xxxxxxxx-xxxxxxxx-xxxxxxxx
' where the x's are A thru F or Zero thru Nine
rx = New Regex("([A-F0-9]{8}\-[A-F0-9]{8}\-[A-F0-9]{8}\-[A-F0-9]{8})", RegexOptions.IgnoreCase)
m = rx.Matches(s)
For Each item In m
    System.Diagnostics.Debug.Print(item.ToString)
Next
于 2013-11-14T21:27:59.680 回答
0

也许我不完全理解,但看起来它是由您寻找的连字符分隔的 8 个字符组?

Imports System.Text.RegularExpressions

Module Example
   Public Sub Main()
      Dim input As String = "the input you have above"
      Dim pattern As String = "[A-Za-z0-9]{8}\-[A-Za-z0-9]{8}\-[A-Za-z0-9]{8}\-[A-Za-z0-9]{8}" 
      Dim m As Match = Regex.Match(input, pattern)
      Do While m.Success 
         Console.WriteLine("'{0}' found at position {1}", m.Value, m.Index)
         m = m.NextMatch()
      Loop                       
   End Sub 
End Module 

http://msdn.microsoft.com/en-us/library/0z2heewz.aspx

于 2013-11-14T21:29:55.163 回答