using System;
using System.Text.RegularExpressions;
string s="this is some thing about england abc,but it isn't about usa abc.";
Regex re= new Regex(@".{4}abc");
MatchCollection mc = re.Matches(s);
foreach (Match m in mc)
  Console.WriteLine(m.Value);

解决方案 »

  1.   

    <HTML>
    <HEAD>
    <title>WebForm3</title>
    <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.0">
    <meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 78px; POSITION: absolute; TOP: 67px" runat="server"></asp:TextBox>
    <asp:Button id="Button1" OnClick="button1_Click" style="Z-INDEX: 102; LEFT: 329px; POSITION: absolute; TOP: 151px" runat="server" Text="Button"></asp:Button>
    </form>
    <Script runat="server" language="vb">
       Dim pStr As String
       Sub Button1_Click(Sender As Object ,e As EventArgs)
           Dim str,tempStr As String
                   Str ="this is some thing about england abc,but it isn't about usa abc."
                   Call GetStr(Str,tempStr)
                   Response.Write(pStr)
       End Sub
       
       Function GetStr(Str As string,tempStr As String) As String
           Dim IntPos As integer
           
           
                   IntPos=InStr(Str,"abc") -4
                   If IntPos >0 Then
                      tempStr =tempStr &" "& Mid(Str,IntPos,4+3)
                      Str = Mid(Str,IntPos + 4 +3)
                      GetStr(Str,tempStr)
                   Else
                      pStr =tempStr
                      Exit Function
                   End If
                   
               End Function
    </Script>
    </body>
    </HTML>以上是经过测试的,没有一点问题,运用了递归函数.其它的变量可自行根据需要设定.