0
我使用以下代碼將TEXT從其他應用程序通過共享菜單發送到我的應用程序,並在EditText中顯示TEXT。如何格式化通過共享菜單發送的文本字符串
Intent receivedIntent = getIntent();
String receivedAction = receivedIntent.getAction();
String receivedType = receivedIntent.getType();
TextView txtView = (EditText) findViewById(R.id.edWord);
//if(receivedAction.equals(Intent.ACTION_SEND)){
if (Intent.ACTION_SEND.equals(receivedAction) && receivedType != null) {
if(receivedType.startsWith("text/")) {
String receivedText = receivedIntent.getStringExtra(Intent.EXTRA_TEXT).toLowerCase();
if (receivedText != null)
{
txtView.setText(receivedText);
txtView.requestFocus();
ListView myList=(ListView) findViewById(R.id.lstWord);
myList.setFocusableInTouchMode(true);
myList.setSelection(0);
}
else
txtView.setText("");
}
}
一切運作良好,即發送文本顯示在我的EditText(在上面的代碼即edWord
)。但問題是,通過共享發送的文本有時由無意義的元素或衍生物組成,例如:"word
,word'
,word,
或looked
,books
,tomatoes
。
現在我想要的是格式化文本,使其僅包含真正的單詞或單詞的基本形式,然後纔將其添加到EditText。
我聽說過approximate string matching
或fuzzy searching
但我不知道如何將它應用於我的代碼。我想知道是否可以給我一些幫助來解決上述問題,至少格式化/剝離非單詞元素。
在此先感謝。