Java源码-一个简单的分词器(Tokenizing Telephone Numbers)
来源:互联网 发布:php个人简历源代码 编辑:程序博客网 时间:2024/04/30 20:22
上个项目是个互联网项目,一个网页上,可能七七八八的加载了很多项功能,包括全文检索功能中的“切词(分词)”逻辑,算是长见识了。
不过,完成下面这个练习后,分词(tokenization)对我而言亲和了许多,说白了,就是字符串拆分。
运行结果:
请输入字符串:86-139-178-67138-1650
请输入分隔符:-
切词结果:86,139,178,67138,1650,
串接结果:86139178671381650
代码如下:
import java.util.*;/**Java how to program, 10th edition 14.8 (Tokenizing Telephone Numbers) Write an application that inputs a telephone number as a string in the form (555) 555-5555. The application should use String method split to extract the area code as a token, the first three digits of the phone number as a token and the last four digits of the phone number as a token. The seven digits of the phone number should be concatenated into one string. Both the area code and the phone number should be printed. Remember that you’ll have to change delimiter characters during the tokenization process. * @author pandenghuang@163.com*/public class Tokenization { public static void main(String[] args) { Scanner input=new Scanner(System.in); System.out.print("请输入字符串:"); String s=input.nextLine(); System.out.print("请输入分隔符:"); String separator=input.nextLine(); String[] tokens=s.split(separator); System.out.printf("切词结果:"); for (String t:tokens) System.out.print(t+","); String combined=""; for (String t:tokens) combined+=t; System.out.printf("%n串接结果:%s%n",combined); } }
0 0
- Java源码-一个简单的分词器(Tokenizing Telephone Numbers)
- 一个简单的中文分词
- 简单的中文分词程序(C#源码)
- 用Python写一个简单的中文分词器
- 【转载】用Python写一个简单的中文分词器
- Tokenizing:java.util.StringTokenizer 类
- Validate US Telephone Numbers
- Validate US Telephone Numbers
- 一个简单的英文分词程序
- 一个简单的中文分词解决方案
- 一个简单的java计算器源码分析
- java IO流中分词器的简单实例
- 简单的java中文分词IK Analyzer
- 简单的NLPIR分词 JAVA 实现
- FCC Validate US Telephone Numbers
- Java 简单分词查询
- IK分词源码讲解(二)-分词器
- 一个简单的文件删除器(源码)
- 《C++Primer》读书笔记——第5章 语句
- Spring 四种注入方式
- 2016多校训练Contest7: 1011 Knights hdu5819
- PHP安全编程之过滤用户输入
- android知识图谱
- Java源码-一个简单的分词器(Tokenizing Telephone Numbers)
- 如何使用git
- canvas
- runtime理解
- hdu2112 HDU Today(dijkstra求单源最短路)
- scroller 广告轮播 手指滑动 +viewpager 广告轮播 手指滑动
- 软件测试之因果图
- 日志的使用Log4j
- php GD2 --1