-
2021-03-06 04:39:58
import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
public class SpellHelper {
//将中文转换为英文
public static String getEname(String name) throws BadHanyuPinyinOutputFormatCombination
{
HanyuPinyinOutputFormat pyFormat = new HanyuPinyinOutputFormat();
pyFormat.setCaseType(HanyuPinyinCaseType.LOWERCASE);
pyFormat.setToneType(HanyuPinyinToneType.WITHOUT_TONE);
pyFormat.setVCharType(HanyuPinyinVCharType.WITH_V);
return PinyinHelper.toHanyuPinyinString(name, pyFormat, "");
}
//姓、名的第一个字母需要为大写
public static String getUpEname(String name) throws BadHanyuPinyinOutputFormatCombination {
char[] strs = name.toCharArray();
String newname = null;
//名字的长度
if (strs.length == 2) {
newname = toUpCase(getEname("" + strs[0])) + " "
+ toUpCase(getEname("" + strs[1]));
} else if (strs.length == 3)
{
newname = toUpCase(getEname("" + strs[0])) + " "
+ toUpCase(getEname("" + strs[1] + strs[2]));
}
else if (strs.length == 4)
{
newname = toUpCase(getEname("" + strs[0] + strs[1])) + " "
+ toUpCase(getEname("" + strs[2] + strs[3]));
} else
{
newname = toUpCase(getEname(name));
}
return newname;
}
//首字母大写
private static String toUpCase(String str) {
StringBuffer newstr = new StringBuffer();
newstr.append((str.substring(0, 1)).toUpperCase()).append(
str.substring(1, str.length()));
return newstr.toString();
}
public static void main(String[] args) throws BadHanyuPinyinOutputFormatCombination {
System.out.println(getUpEname("李宇春"));
}
}
com.belerweb
pinyin4j
2.5.0
更多相关内容 -
中文地址与英文地址
2022-06-22 22:38:452. 中文地址英译服务 邮政业务 -> 中文地址英译 https://www.post.gov.tw/post/internet/Group/default.jsp 中文地址英译 https://www.post.gov.tw/post/internet/Postal/index.jsp?ID=207 3. 国外邮政国名/地区...中文地址与英文地址 1. 中文地址英译
中文 英文 缩写 省 Province - 市 City - 县 County - 区 District Dist. 街 Street St. 乡 / 镇 Township - 村 Village Vil. 路 Road Rd. 段 Section Sec. 巷 Lane Ln. 弄 Alley Aly. 号 Number No. 楼 Floor F. 室 Room Rm. 东 East E. 西 West W. 南 South S. 北 North N. 重庆市沙坪坝区壮志路 33 号四川外国语大学 Sichuan International Studies University, No. 33, Zhuangzhi Road, Shapingba District, Chongqing, China
2. 中文地址英译服务
1.
邮政业务 -> 中文地址英译
https://www.post.gov.tw/post/internet/Group/default.jsp
2.
中文地址英译
https://www.post.gov.tw/post/internet/Postal/index.jsp?ID=207
Nanjing W. Rd., Zhongshan Dist., Taipei City
3. 国外邮政国名/地区名中英文对照表
https://www.post.gov.tw/post/internet/Postal/sz_a_e_info.jsp
References
https://yongqiang.blog.csdn.net/
http://www.edu-fair.com/Fair/TranslateAddress.html -
中文地址自动翻译为英文地址
2017-11-14 17:24:00[url]http://www.chinafanyi.com/add/index.asp[/url]申请 Intel®64 and IA-32 Architectures Software Developer's Manuals的地址:[url]http://www.intel.com/products/processor/manuals/index...[url]http://www.chinafanyi.com/add/index.asp[/url]
申请 Intel ® 64 and IA-32 Architectures Software Developer's Manuals的地址:
[url]http://www.intel.com/products/processor/manuals/index.htm[/url]
本文转自 h2appy 51CTO博客,原文链接:http://blog.51cto.com/h2appy/133195,如需转载请自行联系原作者 -
Android 定位地址,获取经纬度,并转换为中文地址
2019-08-02 16:53:51Android 定位地址,获取经纬度,并转换为中文地址Android 定位地址,获取经纬度,并转换为中文地址第一步,判断应用是否开启了位置定位的权限功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接...Android 定位地址,获取经纬度,并转换为中文地址
Android 定位地址,获取经纬度,并转换为中文地址
不用百度和谷歌等api,直接获取经纬度,并根据获取到的经纬度转换为中文地址
第一步,判断应用是否开启了位置定位的权限
首先判断应用是否开启了位置定位的权限(没有开启时会弹出开启权限的提示框,若已经开启权限,就执行后续的操作):
/** * 检测位置权限 * @param activity */ public static void checkLocationPermission(Activity activity){ Context context = activity; //获取权限(如果没有开启权限,会弹出对话框,询问是否开启权限) if (ContextCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED || ActivityCompat.checkSelfPermission(activity, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { //请求权限 ActivityCompat.requestPermissions(activity, new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION}, LOCATION_CODE); } else { JudgeIMLine(context); } }
第二步,重写onRequestPermissionsResult方法来监控权限的变化。
当用户权限变化时,此回调方法会被调用:
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { super.onRequestPermissionsResult(requestCode, permissions, grantResults); switch (requestCode) { case LOCATION_CODE: if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED && grantResults[1] == PackageManager.PERMISSION_GRANTED) { // 权限被用户同意。 Util.JudgeIMLine(this); } else { } break; } }
第三步,写一个方法来获取当前手机能提供的位置提供器。
具体方法实现如下:
/** * 获取位置提供器 * @param locationManager * @return */ public static String judgeProvider(LocationManager locationManager,Context context) { List<String> prodiverlist = locationManager.getProviders(true); if(prodiverlist.contains(LocationManager.NETWORK_PROVIDER)){ return LocationManager.NETWORK_PROVIDER;//网络定位 }else if(prodiverlist.contains(LocationManager.GPS_PROVIDER)) { return LocationManager.GPS_PROVIDER;//GPS定位 }else { //Toast.makeText(context,"没有可用的位置提供器",Toast.LENGTH_SHORT).show(); } return null; }
第四步,写一个方法来定位的位置。
此方法返回Location对象,里面包含了经纬度等一系列信息
/** * 定位位置 * @return */ public static Location beginLocatioon(Context context) { //获得位置服务 LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); String provider = judgeProvider(lm,context); //有位置提供器的情况 if (provider != null) { //为了压制getLastKnownLocation方法的警告 if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return null; } return lm.getLastKnownLocation(provider); }else{ //不存在位置提供器的情况 //Toast.makeText(context,"不存在位置提供器的情况",Toast.LENGTH_SHORT).show(); } return null; }
第五步,把获取到的经纬度转换为中文的具体地址。
由于我们获取到的Location只是一个经纬度是普通人无法识别的地址,此处需要进行转换。代码中addresses 获取到的地址格式为:
[{“adminArea”:“重庆市”,“countryCode”:“CN”,“countryName”:“中国”,“latitude”:29.52302920290576,“locale”:“zh_CN”,“locality”:“重庆市”,“longitude”:106.52634124832649,“maxAddressLineIndex”:10,“subLocality”:“九龙坡区”,“subThoroughfare”:"",“thoroughfare”:“万象润街”}]
具体实现代码如下:
/** * 将经纬度转换成中文地址 * * @param location * @return */ public static String getLocationAddress(Location location,Context context) { String countryCode = ""; Geocoder geoCoder = new Geocoder(context); try { List<Address> addresses = geoCoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1); if (addresses!=null&&addresses.size()>0){ Address address = addresses.get(0); countryCode = address.getCountryCode(); } } catch (IOException e) { countryCode = "CN"; e.printStackTrace(); } return countryCode; }
第六步,写一个方法来接收返回的中文地址。
注意:代码中在调用getLocationAddress方法进行转中文地址时,开了个线程。这里必须要开线程,不然就无法进行转换。
/** * 判断登录线路 * * @return */ public static void JudgeIMLine(final Context context) { final Location location = beginLocatioon(context); if (location!=null){ final String[] countryCode = new String[1]; new Thread(new Runnable() { @Override public void run() { countryCode[0] = Util.getLocationAddress(location, context); if (countryCode!=null&&countryCode.length>0) { if ("CN".equals(countryCode[0])) { choiceCNLine(context); }else { //选择别的线路 } }else { choiceCNLine(context); } } }).start(); }else { choiceCNLine(context); } }
最后一步,当然我定位到地址后就执行了自己要执行的操作。
此处我获取到应用登录位置是中国,CN的时候就设置了中国的服务器地址。
/** * 选择国内线路 */ public static void choiceCNLine(Context context){ ShippingApp.getInstance().urlhost = context.getString(R.string.local_service_platform); ShippingApp.getInstance().urlChatHost = context.getString(R.string.chat_service_platform); ShippingApp.getInstance().phoneNum = context.getString(R.string.phoneNum); }
整个实现过程中需要注意的是,当位置权限没有开启的时候,judgeProvider此方法获取的数据是空的。在没有开线程的时候,getLocationAddress这个方法无法正常的把经纬度转换为中文具体地址。
当然,不要忘记在 AndroidManifest.xml文件中添加下面三个权限。 -
中文地址翻译成英文地址方法和技巧
2011-11-29 11:21:13中文地址翻译成英文地址方法和技巧,蛮好用的。 -
网络地址转换NAT原理及其作用
2018-04-17 17:28:001 概述1.1 简介NAT英文全称是“Network Address Translation”,中文意思是“网络地址转换”,它是一个IETF(Internet Engineering Task Force, Internet工程任务组)标准,允许一个整体机构以一个公用IP... -
Java中如何将中文转换为英文String
2019-06-27 11:00:29在JAVA 编程中我们经常免不了需要对中文排序,而往往我们排序的依据就是中文的首字母,当然无论依据什么排序,我们都需要将中文转换成为String 首先,我们要调用一个库pinyin4j-2.5.0.jar 下载地址:... -
地址解析:使用Google API将地址文本转换为经纬度
2022-04-05 18:03:11本文将提供Geocoding API的基础使用指南,包括:设置谷歌云平台账号及项目、基础地址请求代码、返回值解析及信息提取 -
一文了解网络地址转换(NAT)
2021-06-30 14:01:12中文意思是“网络地址转换”,它是一个IETF(Internet Engineering Task Force, Internet工程任务组)标准,允许一个整体机构以一个公用IP(Internet Protocol)地址出现在Internet上 顾名思义,它是一种把内部私有... -
华为路由器:NAT地址转换技术
2022-06-04 11:26:20NAT英文全称是“Network Address Translation”,中文意思是“网络地址转换”,它是一个IETF(Internet Engineering Task Force, Internet工程任务组)标准,允许一个整体机构以一个公用IP(Internet Protocol)地址... -
网络地址转换
2020-03-26 23:22:50在计算器网络中,网络地址转换(Network Address Translation,缩写为NAT),也叫做网络掩蔽或者IP掩蔽(IP masquerading),是一种在IP数据包通过路由器或防火墙时重写来源IP地址或目的IP地址的技术。这种技术被... -
VSCode 中文英文版设置大小写转换的快捷键 vscode快捷键官方文档地址
2021-06-24 20:00:02转换大小写是文本编辑中一个很常用的操作。 而VSCode中默认是没有绑定该功能的快捷键的,需要自己绑定。... 设置转换大小写的快捷键英文搜索transform(中文版搜索:转换为大写),可以查询到两项: Transform to..... -
网络地址转换(NAT)原理简介
2010-05-21 09:23:39NAT英文全称是“Network Address Translation”,中文意思是“网络地址转换”,它是一个IETF(Internet Engineering Task Force, Internet工程任务组)标准,允许一个整体机构以一个公用IP(Internet Protocol)地址... -
网络地址转换NAT原理及应用
2017-12-04 18:28:54NAT英文全称是“Network Address Translation”,中文意思是“网络地址转换”,它是一个IETF(Internet Engineering Task Force, Internet工程任务组)标准,允许一个整体机构以一个公用IP(Internet Protocol)地址... -
python中将中文汉字转换为英文首字母的代码及遇到的小问题
2016-08-01 17:26:56python中将中文汉字转换为英文首字母的代码及遇到的小问题 在地名地址工作中,有一步是将属性表中的单位汉字名称转换为对应的英文首字母名称 def multi_get_letter(str_input): if isinstance(str_input, unicode... -
网络地址转换NAT原理
2019-05-30 17:33:12NAT英文全称是“NetworkAddressTranslation”,中文意思是“网络地址转换”,它是一个IETF标准,允许一个整体机构以一个公用IP(InternetProtocol)地址出现在Internet上。顾名思义,它是一种把内部私有网络地址(IP... -
网络地址转换NAT原理(易于理解)
2022-01-12 22:01:40这是做路由器的时候,学习网络地址转换NetworkAddressTranslation后的一些理解整理,主要通过实例和图表的方式展示了NAT的工作原理和每个阶段的状态。本文的NAT是基本于Linux下的iptables命令实现。 1概述 1.1简介... -
asp 中文姓名转换成英文姓名、朝鲜文姓名、韩文姓名(纯字库翻译,丹东-朝鲜通关已验证)
2019-04-11 10:48:09ASP编写,中文姓名转换成朝文,中文转英文,纯字库翻译,并非Unicode转换 测试地址:http://www.i0415.net/xingmingfanyi.asp 本程序虽已公开代码,但商业用途请联系作者购买版权 -
URL编码与中文相互转换
2022-06-06 08:55:33URL编码与中文的相互转换 -
中文地址翻译成英文实例
2014-05-18 10:49:11中文地址: 北京市海淀区东北旺西路8号中关村软件园9号楼3区D座 100193 英文翻译: Tower D, 3rd Block, Zhongguancun Software Park, Building 9, 8 Dongbeiwang West Road, Haidian District,... -
NAT、Napt(地址转换技术)详解
2020-06-23 11:31:45如果我们把Internet比作一个邮政系统,那么IP地址的作用就等同于包含城市、街区、门牌编号在内的完整地址。IPv4使用32bits整数表达一个地址,地址最大范围就是232 约为43亿。以IP创始时期可被联网的设备来看,这样的...