2011-12-24 9 views
-3

私はRegexで何かをコード化するためにコーダーを雇った。問題は、Visual Basicでコード化していて、C#でそれが必要だということでした。VB.NETからRegexをC#に変換するためのヘルプが必要

私はコンバータを使用してみましたが、問題を修正しませんでした。

私は、次の正規表現をC#に変換するのを手伝っていますか?

string iamtwit = ss("http://www.mailinator.com" + GetBetween(GetBetween(iamtwit1, matches.ToString(), "</a>"), "<a href=", ">")); 

MessageBox.Show(GetBetween(matches1.ToString(), "<a href=\"", Strings.Chr(34))); 

ここでは、元のコードです:

Dim iamtwit As String = ss("http://www.mailinator.com" & GetBetween(GetBetween(iamtwit1, matches.ToString, "</a>"), "<a href=", ">")) 


MsgBox(GetBetween(matches1.ToString, "<a href=""", Chr(34))) 

私は取得していますエラーメッセージは次のとおりです。

問題は、おかげでGetBetweenと文字列にしています

名前 'GetBetween'は現在のコンテキストに存在しません

名「文字列は」は現在のコンテキスト

+0

...セミコロンを気づく:C#に変換さ

? VB.NETコードを投稿して、何が起こっているのかを正確に確認してください。 – SQLMason

+0

しかし、私はラインでエラーが発生しています:GetBetween – user1017524

+0

GetBetweenは関数です...おそらくVB.NETコードから変換する必要があります – SQLMason

答えて

1
private string getBetween(string strSource, string strStart, string strEnd) 
     { 
      int Start, End; 
      if (strSource.Contains(Starting) && strSource.Contains(Ending)) 
      { 
       Start = strSource.IndexOf(Starting, 0) + strStart.Length; 
       End = strSource.IndexOf(strEnd, Start); 
       return strSource.Substring(Start, End - Start); 
      } 
      else 
      { 
       return ""; 
      } 
     } 
+0

It worked :)... – user1017524

+2

Contains is just a wrapper around the IndexOf function. You should call directly IndexOf and check if the result is -1 –

+0

I agree with not using 'Contains'. However, it's not for the (probably micro)optimization of only searching the string once, but rather that the current implementation throws when called as 'getBetween("テスト"、 "" 、 "") 'また、' Starting'と 'Ending'を定義せずに使用しています。 –

1

あなたがC#のではなく、VB.NETに掲載のコードには存在しません。また、正規表現は含まれていません。

すでに行っているように、アセンブリをインポートして直接使用します。私はあなたがGetBetweenメソッドが必要と仮定しています。

.NETのポイントの1つは、人々が異なる言語を使用し、それらと相互運用できるということです。

+0

How do I fix the Getbetween issue? – user1017524

+2

@user1017524 - You didn't actually explain what the issue _is_. – Oded

2

GetBetweenはthis articleのコードです。

のC#で
public string GetBetween(string sSearch, string sStart, string sStop, int lSearch = 1) 
    { 
     string retVal = null; 
     lSearch = (sSearch.IndexOf(sStart, lSearch - 1, StringComparison.InvariantCultureIgnoreCase) + 1); 
     if (lSearch > 0) 
     { 
      lSearch = lSearch + sStart.Length; 
      int lTemp = 0; 
      lTemp = (sSearch.IndexOf(sStop, lSearch - 1) + 1); 
      if (lTemp > lSearch) 
      { 
       retVal = sSearch.Substring(lSearch - 1, lTemp - lSearch); 
      } 
     } 
     return retVal; 
    } 
関連する問題