2012-05-12 7 views
-3

私はアンドロイドアプリケーションを開発しており、EditTextの中にあるリンクを認識したいと思います。私はobjective-cで動作する次のコードを持っています。私はjavaでそれをやりたいのです。私はそれがベクトル(文字列リンク[])と関係があると思いますが、わかりません。 downvoteのためAndroid用Javaへのリンクを認識するためのObjective-Cコードの翻訳

import java.net.URL; 
import java.util.List; 

String input = /* text from edit text */; 

String[] words = input.split("\\s"); 
List<URL> urls; 

for (String s : words) 
{ 
    try 
    { 
     urls.add(new URL(s)); 
    } 
    catch (MalformedURLException e) 
    { 
     // not a url 
    } 
} 

// urls contains all urls from 'input'. 
+3

申し訳ありませんが、私は「私のために仕事をする」という質問としてこれを読んで:

NSError *qwerror = nil; NSRegularExpression *qwregex = [NSRegularExpression regularExpressionWithPattern:@"(http://\\w+.\\w+.\\w+.\\w+.\\w+.)" options:0 error:&qwerror]; NSArray *qwmatches = [qwregex matchesInString:textView.text options:0 range:NSMakeRange(0, textView.text.length)]; NSMutableArray *qwwords = [NSMutableArray array]; for (NSTextCheckingResult *qwmatch in qwmatches) { NSRange qwwordrange = [qwmatch rangeAtIndex:1]; NSString *qwword = [textView.text substringWithRange:qwwordrange]; [qwwords addObject:qwword]; } NSString *allLinks = [qwwords componentsJoinedByString:@" "]; 
Medo42

答えて

0

は、これが動作する可能性があります。できるだけ多くの仕事をして、具体的な詳細について質問してください。私たちの前でタスク全体を設定したり、コードを尋ねたりしないでください。
+0

なぜ賛成投票ですか?これは、URLを解析する正しい方法です。Javaでは、そうではありませんか? –

+0

ありがとう –

関連する問題