删除 android 中的字符串的一部分
Removing a part of a string in android
我有一个应用程序,它具有 TextToSpeech
功能,可以阅读编辑文本中的大量单词,这是我的代码:
package com.example.texttoSPCH;
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.Locale;
public class MyActivity extends Activity implements TextToSpeech.OnInitListener {
TextToSpeech tts;
EditText edt;
Button btn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SpeakOut();
}
});
}
private void init() {
edt= (EditText) findViewById(R.id.edt);
btn= (Button) findViewById(R.id.btn);
tts=new TextToSpeech(this,this);
}
@Override
public void onInit(int status) {
if (status==TextToSpeech.SUCCESS) {
tts.setLanguage(Locale.US);
}
if (status==TextToSpeech.LANG_MISSING_DATA){
Toast.makeText(getApplicationContext(),"Text To Speech is not supported",Toast.LENGTH_LONG).show();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
tts.shutdown();
}
private void SpeakOut() {
String text=edt.getText().toString();
if (null==text||"".equals(text)){
text="Please give some input";
}
tts.speak(text,TextToSpeech.QUEUE_FLUSH,null);
}
}
我有一些词看起来像这个:ability (n.),或者这个:dizzy (adj.),但我不想 TTS
读那种单词。有什么办法吗?喜欢 :
if(text.contains("(n.)"){
String newtext = text-"(n.)"
}
然后告诉 TTS
阅读 newtext
?
String stringToRemove = "(n.)";
if(text.contains(stringToRemove){
String newtext = text.replaceAll(stringToRemove, "");
}
希望有用。
我有一个应用程序,它具有 TextToSpeech
功能,可以阅读编辑文本中的大量单词,这是我的代码:
package com.example.texttoSPCH;
import android.app.Activity;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.util.Locale;
public class MyActivity extends Activity implements TextToSpeech.OnInitListener {
TextToSpeech tts;
EditText edt;
Button btn;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
init();
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SpeakOut();
}
});
}
private void init() {
edt= (EditText) findViewById(R.id.edt);
btn= (Button) findViewById(R.id.btn);
tts=new TextToSpeech(this,this);
}
@Override
public void onInit(int status) {
if (status==TextToSpeech.SUCCESS) {
tts.setLanguage(Locale.US);
}
if (status==TextToSpeech.LANG_MISSING_DATA){
Toast.makeText(getApplicationContext(),"Text To Speech is not supported",Toast.LENGTH_LONG).show();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
tts.shutdown();
}
private void SpeakOut() {
String text=edt.getText().toString();
if (null==text||"".equals(text)){
text="Please give some input";
}
tts.speak(text,TextToSpeech.QUEUE_FLUSH,null);
}
}
我有一些词看起来像这个:ability (n.),或者这个:dizzy (adj.),但我不想 TTS
读那种单词。有什么办法吗?喜欢 :
if(text.contains("(n.)"){
String newtext = text-"(n.)"
}
然后告诉 TTS
阅读 newtext
?
String stringToRemove = "(n.)";
if(text.contains(stringToRemove){
String newtext = text.replaceAll(stringToRemove, "");
}
希望有用。