我怎么能得到全名的第一个字母(名字,姓氏)? [英] How I can get the first letter for full name (first name , last name)?

查看:153
本文介绍了我怎么能得到全名的第一个字母(名字,姓氏)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获得全名的第一个字母(名字,姓氏)?



我希望用户输入你的姓名和姓氏,我会得到拳头名字的第一个字母和姓氏合并在一起的第一个字母。



这是订单

1.读取用户全名

2.取第一个名字和姓氏。

3.将它们设为大写和合并

示例Stephen Ricard

输出= SR



我想要简单。

非常感谢



我尝试了什么: < br $> b $ b

我知道如何通过charAt(0)得到第一个字母,但我不知道第二个字。

How I can get the first letter for full name (First name , Last name)?

I want from the user enter your name and last name than I will get the fist letter for fist name and fist letter for last name merge together .

This is the order
1. Read User Full Name
2. Take 1st literal of First and Last name.
3. Make them Upper Case and Merge
example Stephen Ricard
Output = SR

please I want be simple.
Thank you very much

What I have tried:

I know how I can get the first letter for fist word by charAt(0) ,but I don't know the second word.

推荐答案

引用:

我知道如何通过charAt获得第一个字母的第一个字母( 0),但我不知道第二个字。

I know how I can get the first letter for fist word by charAt(0) ,but I don't know the second word.

好的,你已经到了一半。



你需要做什么是从t中提取名字和姓氏用户输入的全名,然后应用 charAt(0)知识获取每个组件的第一个字母。 最后,将要返回的文本转换为大写,然后就完成了。



/ ravi

OK, you're halfway there.

What you need to do is extract the first and last name from the full name entered by the user, then apply your charAt(0) knowledge to get the first letter of each component.  Finally, convert the text to be returned to uppercase and you're done.

/ravi


试试以下 -

Try following-
String x = "Stephen Ricard";
String[] nameparts = x.split(" ");
String initials = nameparts[0].charAt(0).toUpperCase()+nameparts[1].charAt(0).toUpperCase(); //Output: SR





希望,它有助于:)



Hope, it helps :)


这篇关于我怎么能得到全名的第一个字母(名字,姓氏)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆