2015-04-22 31 views
-3

這裏是我的問題描述,我想在java字符串的段落中找到給定的模式?

String str="We may use the name you provide for your Google Profile across all of the services we offer that require a Google Account. In addition, we may replace past names associated with your Google Account so that you are represented consistently across all our services. If other users already have your email, or other information"; 

現在,

String pat="we offer"; 

,所以我需要找到字符串「海峽」模式「拍」,也是我需要的話用同樣的模式開始...就像「我們可能」,「和你一起......」等等。

+4

幫助你什麼?用現成的代碼? – Maroun

+1

嘗試使用String.split()方法..並張貼您發佈問題時發佈的內容 – prasadmadanayake

回答

1

首先,您可以將字符串pat的段落分開。然後比較'pat'附近的單詞並找到您需要的模式。

public class Test { 

    public static void main(String[] args) { 
     String a="We may use the name you provide for your Google Profile across all of the services we offer that require a Google Account. In addition, we may replace past names associated with your Google Account so that you are represented consistently across all our services. If other users already have your email, or other information"; 
     String b="we offer"; 
    String[] s= a.split(b); 
    System.out.print("==============="+s[0]); 
    System.out.print("==============="+s[1]); 
     } 
} 

這只是一個想法,不是一個正確的代碼。請做驗證和異常處理。

+0

Thankyou very much Hasanthi ..! – user3159901

相關問題