Android前端判断敏感词汇
来源:互联网 发布:淘宝店怎么提升销量 编辑:程序博客网 时间:2024/05/01 19:34
敏感词汇通常会在后台进行判断,但偶尔也会有在前端进行判断,其实很简单,就是对一个
字符串中特定字符的替换。
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="visahall.cn.xiaoxin.MainActivity"> <Button android:id="@+id/btn" android:text="点击确定把EditText中的字显示在TextView" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_alignParentStart="true" /> <TextView android:id="@+id/text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" android:layout_below="@+id/btn" android:layout_centerHorizontal="true" android:layout_marginTop="196dp" /> <EditText android:id="@+id/edit" android:hint="敏感字为 美国, 西班牙, 德玛西亚" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/btn" android:layout_alignParentStart="true" /></RelativeLayout>2.MainActivity:
public class MainActivity extends AppCompatActivity { private Button button; private EditText editText; private TextView textView; private List<String> list = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); init(); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String aa = String.valueOf(editText.getText()); for (int i = 0; i < list.size(); i++) { String x = list.get(i); //x为敏感词汇 if (aa.contains(x)){ aa = aa.replaceAll(x, getXing(x)); } } textView.setText(aa); } }); } private void init() { button = (Button) findViewById(R.id.btn); editText = (EditText) findViewById(R.id.edit); textView = (TextView) findViewById(R.id.text); list.add("美国"); list.add("西班牙"); list.add("德玛西亚"); } //得到"*"的数量,然后进行替换相应的字符串 private String getXing(String f){ String a = ""; for (int i = 0; i < f.length(); i++) { a = a + "*"; } return a; }}
Demo下载
0 0
- Android前端判断敏感词汇
- 2017百度前端编程 敏感词汇 字符串替换
- thinkphp读取文件,写一个敏感词汇判断方法
- Java实现敏感词过滤(判断一个句子是否包含敏感词汇)
- 过滤器-过滤敏感词汇
- 屏蔽敏感词汇&KMP
- 屏蔽敏感词汇&KMP
- PHP 敏感词汇过滤
- 过滤敏感词汇
- 过滤敏感词汇
- 过滤敏感词汇
- 过滤敏感词汇
- 过滤敏感词汇
- 过滤敏感词汇
- 过滤敏感词汇
- Msyql过滤敏感词汇语句
- Java作业整理 敏感词汇
- 敏感词汇过滤DFA算法
- Git与TortoiseGit基本操作
- swap函数的泛型
- android 解决部分手机连接热点wifi导致被切换,enablenetwork(netID, true)无效的问题
- 判断用户输入的银行卡号是否正确--基于Luhn算法的格式校验
- UDP接收实例
- Android前端判断敏感词汇
- java.util.concurrent之ForkJoin
- Windows下查询域名的DNS TXT记录的命令
- poj_2065 SETI(高斯消元解同余方程组)
- hashmapper的使用以及json字符串与普通字符串的差异
- Linux下使用shell解压打包jar包
- 【算法模板】图论
- apache 配置动静分离,允许跨域, 并在反向代理的情况下维持默认主页
- pjsip